Class: Eldr::Recognizer

Inherits:
Object
  • Object
show all
Defined in:
lib/eldr/recognizer.rb

Defined Under Namespace

Classes: NotFound

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#appObject

Returns the value of attribute app.



11
12
13
# File 'lib/eldr/recognizer.rb', line 11

def app
  @app
end

#envObject

Returns the value of attribute env.



11
12
13
# File 'lib/eldr/recognizer.rb', line 11

def env
  @env
end

#patternObject

Returns the value of attribute pattern.



11
12
13
# File 'lib/eldr/recognizer.rb', line 11

def pattern
  @pattern
end

#routesObject

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

Raises:



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

#verbObject



31
32
33
# File 'lib/eldr/recognizer.rb', line 31

def verb
  env['REQUEST_METHOD'].downcase.to_sym
end