123456789_123456789_123456789_123456789_123456789_

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

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: ActionDispatch::Routing::Endpoint
Defined in: actionpack/lib/action_dispatch/routing/mapper.rb

Constant Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(app, constraints, strategy) ⇒ Constraints

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 33

def initialize(app, constraints, strategy)
  # Unwrap Constraints objects. I don't actually think it's possible
  # to pass a Constraints object to this constructor, but there were
  # multiple places that kept testing children of this object. I
  # *think* they were just being defensive, but I have no idea.
  if app.is_a?(self.class)
    constraints += app.constraints
    app = app.app
  end

  @strategy = strategy

  @app, @constraints, = app, constraints
end

Instance Attribute Details

#app (readonly)

[ GitHub ]

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

attr_reader :app, :constraints

#constraints (readonly)

[ GitHub ]

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

attr_reader :app, :constraints

#dispatcher?Boolean (readonly)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 48

def dispatcher?; @strategy == SERVE; end

Instance Method Details

#constraint_args(constraint, request) (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 64

def constraint_args(constraint, request)
  arity = if constraint.respond_to?(:arity)
    constraint.arity
  else
    constraint.method(:call).arity
  end

  if arity < 1
    []
  elsif arity == 1
    [request]
  else
    [request.path_parameters, request]
  end
end

#matches?(req) ⇒ Boolean

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 50

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

#serve(req)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/routing/mapper.rb', line 57

def serve(req)
  return [ 404, { Constants::X_CASCADE => "pass" }, [] ] unless matches?(req)

  @strategy.call @app, req
end