Created
June 2, 2011 02:22
-
-
Save k2052/1003798 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
class AllButPattern | |
@@match = Struct.new(:captures) | |
def initialize(app, *exceptions) | |
@controller = app.current_controller | |
@app = app | |
@exceptions = exceptions | |
@captures = @@match.new([]) | |
end | |
def match(str) | |
if @exceptions.first.is_a?(Symbol) | |
@exceptions.each do |except| | |
if except.to_s.index('_') | |
if @app.router.runner.params.empty? | |
return @captures if @app.router.named_routes[except].path != str | |
else | |
return @captures if @app.router.named_routes[except].url(@app.router.runner.params)[0] != str | |
end | |
else | |
route_name = @controller.to_s << '_' << except.to_s | |
if @app.router.runner.params.empty? | |
return @captures if @app.router.named_routes[route_name.to_sym].path != str | |
else | |
return @captures if @app.router.named_routes[route_name.to_sym].url(@app.router.runner.params)[0] != str | |
end | |
end | |
end | |
elsif @exceptions.is_a?(Array) | |
@captures unless @exceptions.include?(str) | |
end | |
false | |
end | |
end | |
def all_but(*args) | |
AllButPattern.new(self, *args) | |
end |
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
Brkit.controllers :user do | |
before all_but(:bob) do | |
puts "you've been hit before?" | |
end | |
get :bob, :map => '/bob' do | |
return 'bobs your uncle' | |
end | |
get :testget, :map => '/testget' do | |
return 'test GET' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment