Module: Rack::Mount::Recognition::Route
- Included in:
- Rack::Mount::Route
- Defined in:
- lib/rack/mount/recognition/route.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#named_captures ⇒ Object
readonly
Returns the value of attribute named_captures.
Instance Method Summary collapse
Instance Attribute Details
#named_captures ⇒ Object (readonly)
Returns the value of attribute named_captures.
6 7 8 |
# File 'lib/rack/mount/recognition/route.rb', line 6 def named_captures @named_captures end |
Instance Method Details
#initialize(*args) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rack/mount/recognition/route.rb', line 8 def initialize(*args) super @named_captures = {} @conditions.map { |method, condition| next unless condition.respond_to?(:named_captures) @named_captures[method] = condition.named_captures.inject({}) { |named_captures, (k, v)| named_captures[k.to_sym] = v.last - 1 named_captures }.freeze } @named_captures.freeze if @conditions.has_key?(:path_info) && !Utils.regexp_anchored?(@conditions[:path_info]) @prefix = true @app = Prefix.new(@app) else @prefix = false end end |
#prefix? ⇒ Boolean
30 31 32 |
# File 'lib/rack/mount/recognition/route.rb', line 30 def prefix? @prefix end |
#recognize(obj) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rack/mount/recognition/route.rb', line 34 def recognize(obj) matches = {} params = @defaults.dup if @conditions.all? { |method, condition| value = obj.send(method) if condition.is_a?(Regexp) && (m = value.match(condition)) matches[method] = m captures = m.captures @named_captures[method].each { |k, i| if v = captures[i] params[k] = v end } true elsif value == condition true else false end } return matches, params else nil end end |