Class: Grape::Router::Route

Inherits:
BaseRoute show all
Extended by:
Forwardable
Defined in:
lib/grape/router/route.rb

Instance Attribute Summary collapse

Attributes inherited from BaseRoute

#index, #options, #pattern

Instance Method Summary collapse

Methods inherited from BaseRoute

#pattern_regexp, #regexp_capture_index, #to_regexp

Constructor Details

#initialize(method, pattern, **options) ⇒ Route

Returns a new instance of Route.



12
13
14
15
16
# File 'lib/grape/router/route.rb', line 12

def initialize(method, pattern, **options)
  @request_method = upcase_method(method)
  @pattern = Grape::Router::Pattern.new(pattern, **options)
  super(**options)
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



8
9
10
# File 'lib/grape/router/route.rb', line 8

def app
  @app
end

#request_methodObject (readonly)

Returns the value of attribute request_method.



8
9
10
# File 'lib/grape/router/route.rb', line 8

def request_method
  @request_method
end

Instance Method Details

#apply(app) ⇒ Object



22
23
24
25
# File 'lib/grape/router/route.rb', line 22

def apply(app)
  @app = app
  self
end

#exec(env) ⇒ Object



18
19
20
# File 'lib/grape/router/route.rb', line 18

def exec(env)
  @app.call(env)
end

#match?(input) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
# File 'lib/grape/router/route.rb', line 27

def match?(input)
  return false if input.blank?

  options[:forward_match] ? input.start_with?(pattern.origin) : pattern.match?(input)
end

#params(input = nil) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/grape/router/route.rb', line 33

def params(input = nil)
  return params_without_input if input.blank?

  parsed = pattern.params(input)
  return {} unless parsed

  parsed.compact.symbolize_keys
end