Class: FitApi::Router::Route

Inherits:
Object
  • Object
show all
Defined in:
lib/fit_api/router/route.rb

Instance Method Summary collapse

Constructor Details

#initialize(verb, path, options = {}) ⇒ Route

Returns a new instance of Route.



16
17
18
19
20
21
22
23
# File 'lib/fit_api/router/route.rb', line 16

def initialize(verb, path, options = {})
  @verb       = verb
  @path       = path
  @controller = get_controller(options)
  @action     = get_action(options)

  require_controller
end

Instance Method Details

#invoke(env) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/fit_api/router/route.rb', line 25

def invoke(env)
  request    = Request.new(env)
  params     = build_params(request)
  controller = Object.const_get("#{@controller.to_s.capitalize}Controller").new(request, params)

  controller.invoke(@action)
rescue Halt
  controller.response
end

#match?(path) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/fit_api/router/route.rb', line 35

def match?(path)
  Parser.new(@path, path).match?
end