sam / harbor

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

Action filters #67

Closed fgrehm closed 12 years ago

fgrehm commented 12 years ago

Done!

The DSL is a bit different than what I originally described on #64:

class PostsController < Harbor::Controller
  # Runs block before any incoming request
  before :all do
    # ...
  end

  # This is a bit tricky and will call "authenticate" instance method after "/posts" requests and not before all requests as it might look to be consistent with the route definition
  before :call => :authenticate

  # Calls "log" instance method after any incoming PUT request
  after :all, :request_method => :put, :call => :log

  # Checks for authentication on all admin requests to this controller
  before '/admin/*', :call => :check_authentication

  # Checks for authorization before updating or creating a new post
  before ':id', :request_method => [:put, :post], :call => :check_authorization
end