Class: Grape::Router::Route

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Route.



19
20
21
22
23
# File 'lib/grape/router/route.rb', line 19

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

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



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

def app
  @app
end

#attributesObject (readonly)

Returns the value of attribute attributes.



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

def attributes
  @attributes
end

#indexObject

Returns the value of attribute index.



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

def index
  @index
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#patternObject (readonly)

Returns the value of attribute pattern.



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

def pattern
  @pattern
end

Instance Method Details

#apply(app) ⇒ Object



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

def apply(app)
  @app = app
  self
end

#exec(env) ⇒ Object



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

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

#match?(input) ⇒ Boolean

Returns:

  • (Boolean)


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

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

  attributes.forward_match ? input.start_with?(pattern.origin) : pattern.match?(input)
end

#params(input = nil) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/grape/router/route.rb', line 40

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

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

  parsed.compact.symbolize_keys
end