Class: ActionDispatch::Routing::Mapper::Constraints
- Defined in:
- lib/action_dispatch/routing/mapper.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#constraints ⇒ Object
readonly
Returns the value of attribute constraints.
Instance Method Summary collapse
- #dispatcher? ⇒ Boolean
-
#initialize(app, constraints, dispatcher_p) ⇒ Constraints
constructor
A new instance of Constraints.
- #matches?(req) ⇒ Boolean
- #serve(req) ⇒ Object
Methods inherited from Endpoint
Constructor Details
#initialize(app, constraints, dispatcher_p) ⇒ Constraints
Returns a new instance of Constraints.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/action_dispatch/routing/mapper.rb', line 21 def initialize(app, constraints, dispatcher_p) # 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 @dispatcher = dispatcher_p @app, @constraints, = app, constraints end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
19 20 21 |
# File 'lib/action_dispatch/routing/mapper.rb', line 19 def app @app end |
#constraints ⇒ Object (readonly)
Returns the value of attribute constraints.
19 20 21 |
# File 'lib/action_dispatch/routing/mapper.rb', line 19 def constraints @constraints end |
Instance Method Details
#dispatcher? ⇒ Boolean
36 |
# File 'lib/action_dispatch/routing/mapper.rb', line 36 def dispatcher?; @dispatcher; end |
#matches?(req) ⇒ Boolean
38 39 40 41 42 43 |
# File 'lib/action_dispatch/routing/mapper.rb', line 38 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) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/action_dispatch/routing/mapper.rb', line 45 def serve(req) return [ 404, {'X-Cascade' => 'pass'}, [] ] unless matches?(req) if dispatcher? @app.serve req else @app.call req.env end end |