Class: Newark::Route::Constraint
- Inherits:
-
Object
- Object
- Newark::Route::Constraint
- Defined in:
- lib/newark/route.rb
Instance Attribute Summary collapse
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#matchers ⇒ Object
readonly
Returns the value of attribute matchers.
Class Method Summary collapse
-
.load(constraints) ⇒ Object
Expects a hash of constraints.
Instance Method Summary collapse
-
#initialize(field, match_or_matchers) ⇒ Constraint
constructor
A new instance of Constraint.
- #match?(request) ⇒ Boolean
Constructor Details
#initialize(field, match_or_matchers) ⇒ Constraint
Returns a new instance of Constraint.
71 72 73 74 |
# File 'lib/newark/route.rb', line 71 def initialize(field, match_or_matchers) @field = field @matchers = make_matchers_regexp(match_or_matchers) end |
Instance Attribute Details
#field ⇒ Object (readonly)
Returns the value of attribute field.
63 64 65 |
# File 'lib/newark/route.rb', line 63 def field @field end |
#matchers ⇒ Object (readonly)
Returns the value of attribute matchers.
63 64 65 |
# File 'lib/newark/route.rb', line 63 def matchers @matchers end |
Class Method Details
.load(constraints) ⇒ Object
Expects a hash of constraints
66 67 68 69 |
# File 'lib/newark/route.rb', line 66 def self.load(constraints) fail ArgumentError unless constraints.is_a?(Hash) constraints.map { |field, matcher| Constraint.new(field, matcher) } end |
Instance Method Details
#match?(request) ⇒ Boolean
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/newark/route.rb', line 76 def match?(request) if request.respond_to?(field) constrained = request.send(field) if matchers.is_a?(Hash) && constrained.is_a?(Hash) hash_match?(request, constrained, matchers) else constrained =~ matchers end end end |