Class: Grape::Router::BaseRoute
- Inherits:
-
Object
- Object
- Grape::Router::BaseRoute
- Extended by:
- Forwardable
- Defined in:
- lib/grape/router/base_route.rb
Direct Known Subclasses
Defined Under Namespace
Classes: CaptureIndexCache
Instance Attribute Summary collapse
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#regexp_capture_group ⇒ Object
readonly
The number of the group this route occupies in the union the router compiled it into.
-
#regexp_capture_index ⇒ Object
readonly
Assigned eagerly in #to_regexp (router compilation) rather than memoized here: this reader is called from request-time route matching on instances shared across threads, so it must not write state.
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
Instance Method Summary collapse
-
#default ⇒ Object
deprecated
Deprecated.
Use #default_response, the name grape-swagger asks for. This one has to be written out rather than delegated like the rest: an ActiveSupport::OrderedOptions answers an unknown name with that key's value, but
defaultis not unknown to it — it isHash#default, the Hash's own default value — so a delegator would report nil for every route. - #failure ⇒ Object
-
#initialize(pattern, options = {}, namespace: nil, prefix: nil, settings: nil) ⇒ BaseRoute
constructor
A new instance of BaseRoute.
- #pattern_regexp ⇒ Object
- #resolve_capture_group!(union_named_captures) ⇒ Object private
-
#success ⇒ Object
successandfailureare thedescDSL's names forentityandhttp_codes: the block form writes the canonical key, a keyword option keeps the name it was written with, so both spellings are read here. - #to_regexp(index) ⇒ Object
Constructor Details
#initialize(pattern, options = {}, namespace: nil, prefix: nil, settings: nil) ⇒ BaseRoute
Returns a new instance of BaseRoute.
17 18 19 20 21 22 23 |
# File 'lib/grape/router/base_route.rb', line 17 def initialize(pattern, = {}, namespace: nil, prefix: nil, settings: nil) @pattern = pattern @options = .is_a?(ActiveSupport::OrderedOptions) ? : ActiveSupport::OrderedOptions.new.update() @namespace = namespace @prefix = prefix @settings = settings end |
Instance Attribute Details
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
10 11 12 |
# File 'lib/grape/router/base_route.rb', line 10 def namespace @namespace end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/grape/router/base_route.rb', line 10 def @options end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
10 11 12 |
# File 'lib/grape/router/base_route.rb', line 10 def pattern @pattern end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
10 11 12 |
# File 'lib/grape/router/base_route.rb', line 10 def prefix @prefix end |
#regexp_capture_group ⇒ Object (readonly)
The number of the group this route occupies in the union the router
compiled it into. Only the union can say what it is, so it is written
back by Grape::Router#compile! right after building one, and like
regexp_capture_index it is never assigned at request time.
58 59 60 |
# File 'lib/grape/router/base_route.rb', line 58 def regexp_capture_group @regexp_capture_group end |
#regexp_capture_index ⇒ Object (readonly)
Assigned eagerly in #to_regexp (router compilation) rather than memoized here: this reader is called from request-time route matching on instances shared across threads, so it must not write state.
52 53 54 |
# File 'lib/grape/router/base_route.rb', line 52 def regexp_capture_index @regexp_capture_index end |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
10 11 12 |
# File 'lib/grape/router/base_route.rb', line 10 def settings @settings end |
Instance Method Details
#default ⇒ Object
Use Grape::Router#default_response, the name grape-swagger asks for.
This one has to be written out rather than delegated like the rest:
an ActiveSupport::OrderedOptions answers an unknown name with that
key's value, but default is not unknown to it — it is Hash#default,
the Hash's own default value — so a delegator would report nil for
every route.
44 45 46 47 |
# File 'lib/grape/router/base_route.rb', line 44 def default Grape.deprecator.warn('`Grape::Router::Route#default` is deprecated. Use `#default_response` instead.') default_response end |
#failure ⇒ Object
34 35 36 |
# File 'lib/grape/router/base_route.rb', line 34 def failure @options[:http_codes] || @options[:failure] end |
#pattern_regexp ⇒ Object
60 61 62 |
# File 'lib/grape/router/base_route.rb', line 60 def pattern_regexp @pattern.to_regexp end |
#resolve_capture_group!(union_named_captures) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
71 72 73 |
# File 'lib/grape/router/base_route.rb', line 71 def resolve_capture_group!(union_named_captures) @regexp_capture_group = union_named_captures.fetch(regexp_capture_index).first end |
#success ⇒ Object
success and failure are the desc DSL's names for entity and
http_codes: the block form writes the canonical key, a keyword option
keeps the name it was written with, so both spellings are read here.
Without this they resolve through delegate_missing_to, which answers
nil for whichever of the two keys the description did not use.
30 31 32 |
# File 'lib/grape/router/base_route.rb', line 30 def success @options[:entity] || @options[:success] end |
#to_regexp(index) ⇒ Object
64 65 66 67 |
# File 'lib/grape/router/base_route.rb', line 64 def to_regexp(index) @regexp_capture_index = CaptureIndexCache[index] Regexp.new("(?<#{regexp_capture_index}>#{pattern_regexp})") end |