Created
April 29, 2010 21:20
-
-
Save foca/384268 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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