Class: ActionDispatch::Routing::Mapper::Constraints

Inherits:
Object
  • Object
show all
Defined in:
actionpack/lib/action_dispatch/routing/mapper.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, constraints, request) ⇒ Constraints

Returns a new instance of Constraints.



28
29
30
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 28

def initialize(app, constraints, request)
  @app, @constraints, @request = app, constraints, request
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app



26
27
28
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 26

def app
  @app
end

#constraintsObject (readonly)

Returns the value of attribute constraints



26
27
28
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 26

def constraints
  @constraints
end

Class Method Details

.new(app, constraints, request = Rack::Request) ⇒ Object



18
19
20
21
22
23
24
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 18

def self.new(app, constraints, request = Rack::Request)
  if constraints.any?
    super(app, constraints, request)
  else
    app
  end
end

Instance Method Details

#call(env) ⇒ Object



43
44
45
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 43

def call(env)
  matches?(env) ? @app.call(env) : [ 404, {'X-Cascade' => 'pass'}, [] ]
end

#matches?(env) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
40
41
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 32

def matches?(env)
  req = @request.new(env)

  @constraints.all? do |constraint|
    (constraint.respond_to?(:matches?) && constraint.matches?(req)) ||
      (constraint.respond_to?(:call) && constraint.call(*constraint_args(constraint, req)))
  end
ensure
  req.reset_parameters
end