sam / harbor

Harbor is a Ruby Web Framework.
https://github.com/sam/harbor
MIT License
3 stars 6 forks source link

Proposal: Action filters #64

Closed fgrehm closed 12 years ago

fgrehm commented 12 years ago

We all know what this is about right? :-P

The usage might be something like the code below:

class Admin::PostsController < Harbor::Controller
  before do
    # ... check for authentication on request.cookies on all incoming requests ...
  end

  # calls some_instance_method after all incoming requests
  after :some_instance_method

  before ":id" => [:delete, :put] do
    # ... check if user is allowed to modify / delete a post ...
  end

  # or the alternative (which I didn't like much)
  before { ":id" => [:delete, :put] }, :authorize

  # support for filter classes
  filter AuthenticationFilter
  filter AuthorizationFilter,  ":id" => [:delete, :put]
end

Any other thoughts / ideas for the "DSL"?

sam commented 12 years ago

Looks good to me. Though I'd probably get rid of filter. The same could be accomplished with before and after, and you could easily duplicate it's functionality within your own modules, so I think it's not worth the growing the API for it.