Skip to content

Instantly share code, notes, and snippets.

@foca
Created April 29, 2010 21:20
Show Gist options
  • Select an option

  • Save foca/384268 to your computer and use it in GitHub Desktop.

Select an option

Save foca/384268 to your computer and use it in GitHub Desktop.
# so everyone uses something like this for request-level authentication in Sinatra
class TestApp < Sinatra::Application
get "/path" do
require_authentication!
...
end
end
# and complain about how sinatra doesn't support per-route before filters like um, "other frameworks"
# well, you can do this to decouple the auth from the route itself:
class TestApp < Sinatra::Application
condition { require_authentication! }
get "/path" do
...
end
end
# and if you feel it needs more DSL-y magic, then:
module BeforeFilters
def before_filter(method)
condition { send method }
end
end
class TestApp < Sinatra::Application
register BeforeFilters
before_filter :require_authentication!
get "/path" do
...
end
end
# Though I don't think the extra DSL is needed, but to each its own :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment