Class: Grape::Router::BaseRoute

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

Direct Known Subclasses

GreedyRoute, Route

Defined Under Namespace

Classes: CaptureIndexCache

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern, options = {}) ⇒ BaseRoute

Returns a new instance of BaseRoute.



15
16
17
18
# File 'lib/grape/router/base_route.rb', line 15

def initialize(pattern, options = {})
  @pattern = pattern
  @options = options.is_a?(ActiveSupport::OrderedOptions) ? options : ActiveSupport::OrderedOptions.new.update(options)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/grape/router/base_route.rb', line 10

def options
  @options
end

#patternObject (readonly)

Returns the value of attribute pattern.



10
11
12
# File 'lib/grape/router/base_route.rb', line 10

def pattern
  @pattern
end

Instance Method Details

#namespaceObject



21
22
23
# File 'lib/grape/router/base_route.rb', line 21

def namespace
  @namespace ||= @options[:namespace]
end

#pattern_regexpObject



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

def pattern_regexp
  @pattern.to_regexp
end

#regexp_capture_indexObject



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

def regexp_capture_index
  @regexp_capture_index ||= CaptureIndexCache[@index]
end

#to_regexp(index) ⇒ Object



33
34
35
36
# File 'lib/grape/router/base_route.rb', line 33

def to_regexp(index)
  @index = index
  Regexp.new("(?<#{regexp_capture_index}>#{pattern_regexp})")
end