Class: Grape::Router::Route

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

Constant Summary collapse

FORWARD_MATCH_METHOD =
->(input, pattern) { input.start_with?(pattern.origin) }
NON_FORWARD_MATCH_METHOD =
->(input, pattern) { pattern.match?(input) }

Instance Attribute Summary collapse

Attributes inherited from BaseRoute

#options, #pattern

Instance Method Summary collapse

Methods inherited from BaseRoute

#namespace, #pattern_regexp, #regexp_capture_index, #to_regexp

Constructor Details

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

Returns a new instance of Route.



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

def initialize(endpoint, method, pattern, options)
  super(pattern, options)
  @app = endpoint
  @request_method = upcase_method(method)
  @match_function = options[:forward_match] ? FORWARD_MATCH_METHOD : NON_FORWARD_MATCH_METHOD
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



11
12
13
# File 'lib/grape/router/route.rb', line 11

def app
  @app
end

#indexObject (readonly)

Returns the value of attribute index.



11
12
13
# File 'lib/grape/router/route.rb', line 11

def index
  @index
end

#request_methodObject (readonly)

Returns the value of attribute request_method.



11
12
13
# File 'lib/grape/router/route.rb', line 11

def request_method
  @request_method
end

Instance Method Details

#apply(app) ⇒ Object



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

def apply(app)
  @app = app
  self
end

#convert_to_head_request!Object



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

def convert_to_head_request!
  @request_method = Rack::HEAD
end

#match?(input) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
# File 'lib/grape/router/route.rb', line 31

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

  @match_function.call(input, pattern)
end

#params(input = nil) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/grape/router/route.rb', line 37

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

  parsed = pattern.params(input)
  return unless parsed

  parsed.compact.symbolize_keys
end