Class: Clutterbuck::Router::Route
- Inherits:
-
Object
- Object
- Clutterbuck::Router::Route
- Defined in:
- lib/clutterbuck/router/route.rb
Overview
A route within the application.
Not something you should ever have to deal with yourself directly, it's part of the internal plumbing of Clutterbuck::Router.
Instance Attribute Summary collapse
-
#path_match ⇒ Object
Returns the value of attribute path_match.
-
#verb ⇒ Object
Returns the value of attribute verb.
Instance Method Summary collapse
-
#handles?(path) ⇒ Boolean
Can this route handle a request for the specified path?.
-
#initialize(verb, path_match, method) ⇒ Route
constructor
A new instance of Route.
-
#run(obj, path) ⇒ Object
Execute the handler for the route.
Constructor Details
#initialize(verb, path_match, method) ⇒ Route
Returns a new instance of Route.
24 25 26 27 28 29 30 31 |
# File 'lib/clutterbuck/router/route.rb', line 24 def initialize(verb, path_match, method) unless path_match.is_a?(String) or path_match.is_a?(Regexp) raise ArgumentError, "path must be either a string or a regexp" end @verb, @path_match, @method = verb, path_match, method end |
Instance Attribute Details
#path_match ⇒ Object
Returns the value of attribute path_match.
12 13 14 |
# File 'lib/clutterbuck/router/route.rb', line 12 def path_match @path_match end |
#verb ⇒ Object
Returns the value of attribute verb.
12 13 14 |
# File 'lib/clutterbuck/router/route.rb', line 12 def verb @verb end |
Instance Method Details
#handles?(path) ⇒ Boolean
Can this route handle a request for the specified path?
39 40 41 42 43 44 45 46 |
# File 'lib/clutterbuck/router/route.rb', line 39 def handles?(path) !!case @path_match when String @path_match == path when Regexp @path_match =~ path end end |
#run(obj, path) ⇒ Object
Execute the handler for the route
Run the method
51 52 53 54 55 56 57 58 |
# File 'lib/clutterbuck/router/route.rb', line 51 def run(obj, path) args = case @path_match when String then [] when Regexp then @path_match.match(path)[1..-1] end @method.bind(obj).call(*args) end |