Class: Reins::Routes::Rule
- Inherits:
-
Object
- Object
- Reins::Routes::Rule
- Defined in:
- lib/reins/routes/rule.rb
Instance Attribute Summary collapse
-
#constraints ⇒ Object
readonly
Returns the value of attribute constraints.
-
#dest ⇒ Object
readonly
Returns the value of attribute dest.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
-
#regexp ⇒ Object
readonly
Returns the value of attribute regexp.
-
#vars ⇒ Object
readonly
Returns the value of attribute vars.
-
#verb ⇒ Object
readonly
Returns the value of attribute verb.
Instance Method Summary collapse
-
#initialize(verb:, pattern:, dest:, name: nil, constraints: {}) ⇒ Rule
constructor
A new instance of Rule.
-
#match(request_verb, path) ⇒ Object
Returns extracted params Hash on a full match, nil otherwise.
-
#matches_path?(path) ⇒ Boolean
True if the path (and constraints) match — verb-agnostic.
- #verb_matches?(request_verb) ⇒ Boolean
- #verbs_for_allow_header ⇒ Object
Constructor Details
#initialize(verb:, pattern:, dest:, name: nil, constraints: {}) ⇒ Rule
Returns a new instance of Rule.
6 7 8 9 10 11 12 13 |
# File 'lib/reins/routes/rule.rb', line 6 def initialize(verb:, pattern:, dest:, name: nil, constraints: {}) @verb = verb @pattern = pattern @dest = dest @name = name @constraints = constraints @vars, @regexp = compile(pattern) end |
Instance Attribute Details
#constraints ⇒ Object (readonly)
Returns the value of attribute constraints.
4 5 6 |
# File 'lib/reins/routes/rule.rb', line 4 def constraints @constraints end |
#dest ⇒ Object (readonly)
Returns the value of attribute dest.
4 5 6 |
# File 'lib/reins/routes/rule.rb', line 4 def dest @dest end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/reins/routes/rule.rb', line 4 def name @name end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
4 5 6 |
# File 'lib/reins/routes/rule.rb', line 4 def pattern @pattern end |
#regexp ⇒ Object (readonly)
Returns the value of attribute regexp.
4 5 6 |
# File 'lib/reins/routes/rule.rb', line 4 def regexp @regexp end |
#vars ⇒ Object (readonly)
Returns the value of attribute vars.
4 5 6 |
# File 'lib/reins/routes/rule.rb', line 4 def vars @vars end |
#verb ⇒ Object (readonly)
Returns the value of attribute verb.
4 5 6 |
# File 'lib/reins/routes/rule.rb', line 4 def verb @verb end |
Instance Method Details
#match(request_verb, path) ⇒ Object
Returns extracted params Hash on a full match, nil otherwise.
16 17 18 19 20 |
# File 'lib/reins/routes/rule.rb', line 16 def match(request_verb, path) return nil unless verb_matches?(request_verb) match_path(path) end |
#matches_path?(path) ⇒ Boolean
True if the path (and constraints) match — verb-agnostic. Used to distinguish 404 from 405.
24 25 26 |
# File 'lib/reins/routes/rule.rb', line 24 def matches_path?(path) !match_path(path).nil? end |
#verb_matches?(request_verb) ⇒ Boolean
28 29 30 |
# File 'lib/reins/routes/rule.rb', line 28 def verb_matches?(request_verb) @verb == :all || @verb == request_verb end |
#verbs_for_allow_header ⇒ Object
32 33 34 |
# File 'lib/reins/routes/rule.rb', line 32 def verbs_for_allow_header @verb == :all ? %w[GET POST PUT PATCH DELETE] : [@verb.to_s.upcase] end |