Module: Rack::Mount::Recognition::RouteSet

Included in:
Rack::Mount::RouteSet
Defined in:
lib/rack/mount/recognition/route_set.rb

Constant Summary collapse

DEFAULT_KEYS =
[:method, [:path_keys_at, 0].freeze].freeze
DEFAULT_CATCH_STATUS =
404

Instance Method Summary collapse

Instance Method Details

#add_route(*args) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/rack/mount/recognition/route_set.rb', line 21

def add_route(*args)
  route = super
  route.throw = @throw

  keys = @recognition_keys.map { |key| route.send(*key) }
  @recognition_graph[*keys] = route

  route
end

#call(env) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rack/mount/recognition/route_set.rb', line 31

def call(env)
  raise 'route set not finalized' unless frozen?

  req = Request.new(env)
  keys = @recognition_keys.map { |key| req.send(*key) }
  @recognition_graph[*keys].each do |route|
    result = route.call(env)
    return result unless result[0] == @catch
  end
  @throw
end

#freezeObject



43
44
45
46
# File 'lib/rack/mount/recognition/route_set.rb', line 43

def freeze
  @recognition_graph.freeze
  super
end

#heightObject

:nodoc:



48
49
50
# File 'lib/rack/mount/recognition/route_set.rb', line 48

def height #:nodoc:
  @recognition_graph.height
end

#initialize(options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rack/mount/recognition/route_set.rb', line 8

def initialize(options = {})
  @catch = options.delete(:catch) || DEFAULT_CATCH_STATUS
  @throw = Const::NOT_FOUND_RESPONSE.dup
  @throw[0] = @catch
  @throw.freeze

  @recognition_keys = options.delete(:keys) || DEFAULT_KEYS
  @recognition_keys.freeze

  @recognition_graph = NestedSet.new
  super
end