Class: Eldr::Recognizer
- Inherits:
-
Object
- Object
- Eldr::Recognizer
- Defined in:
- lib/eldr/recognizer.rb
Defined Under Namespace
Classes: NotFound
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
-
#env ⇒ Object
Returns the value of attribute env.
-
#pattern ⇒ Object
Returns the value of attribute pattern.
-
#routes ⇒ Object
Returns the value of attribute routes.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(routes) ⇒ Recognizer
constructor
A new instance of Recognizer.
- #verb ⇒ Object
Constructor Details
#initialize(routes) ⇒ Recognizer
Returns a new instance of Recognizer.
13 14 15 |
# File 'lib/eldr/recognizer.rb', line 13 def initialize(routes) @routes = routes end |
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
11 12 13 |
# File 'lib/eldr/recognizer.rb', line 11 def app @app end |
#env ⇒ Object
Returns the value of attribute env.
11 12 13 |
# File 'lib/eldr/recognizer.rb', line 11 def env @env end |
#pattern ⇒ Object
Returns the value of attribute pattern.
11 12 13 |
# File 'lib/eldr/recognizer.rb', line 11 def pattern @pattern end |
#routes ⇒ Object
Returns the value of attribute routes.
11 12 13 |
# File 'lib/eldr/recognizer.rb', line 11 def routes @routes end |
Instance Method Details
#call(env) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/eldr/recognizer.rb', line 17 def call(env) @env = env ret_routes = routes[verb].select { |route| !route.match(pattern).nil? } raise NotFound if ret_routes.empty? ret_routes end |
#verb ⇒ Object
31 32 33 |
# File 'lib/eldr/recognizer.rb', line 31 def verb env['REQUEST_METHOD'].downcase.to_sym end |