Class: Interpol::StatusCodeMatcher
- Inherits:
-
Object
- Object
- Interpol::StatusCodeMatcher
- Defined in:
- lib/interpol/endpoint.rb
Overview
Holds the acceptable status codes for an enpoint entry Acceptable status code are either exact status codes (200, 404, etc) or partial status codes (2xx, 3xx, 4xx, etc). Currently, partial status codes can only be a digit followed by two lower-case x’s.
Instance Attribute Summary collapse
-
#code_strings ⇒ Object
readonly
Returns the value of attribute code_strings.
Instance Method Summary collapse
- #example_status_code ⇒ Object
-
#initialize(codes) ⇒ StatusCodeMatcher
constructor
A new instance of StatusCodeMatcher.
- #matches?(status_code) ⇒ Boolean
Constructor Details
#initialize(codes) ⇒ StatusCodeMatcher
Returns a new instance of StatusCodeMatcher.
314 315 316 317 318 |
# File 'lib/interpol/endpoint.rb', line 314 def initialize(codes) codes = ["xxx"] if Array(codes).empty? @code_strings = codes validate! end |
Instance Attribute Details
#code_strings ⇒ Object (readonly)
Returns the value of attribute code_strings.
312 313 314 |
# File 'lib/interpol/endpoint.rb', line 312 def code_strings @code_strings end |
Instance Method Details
#example_status_code ⇒ Object
324 325 326 327 328 329 330 |
# File 'lib/interpol/endpoint.rb', line 324 def example_status_code example_status_code = "200" code_strings.first.chars.each_with_index do |char, index| example_status_code[index] = char if char != 'x' end example_status_code end |
#matches?(status_code) ⇒ Boolean
320 321 322 |
# File 'lib/interpol/endpoint.rb', line 320 def matches?(status_code) code_regexes.any? { |re| re =~ status_code.to_s } end |