class Nucleo::Utilities::StatusCodeMapper
Constants
- STATUS_MAP
Public Class Methods
new(*statuses)
click to toggle source
Returns a utility object to map HTTP status codes to their corresponding ranges
@param statuses [Array] Symbols or status codes
@return [Nucleo::StatusCodeMapper] Instance of the object
# File lib/nucleo/utilities/status_code_mapper.rb, line 18 def initialize(*statuses) @statuses = Array(statuses).flatten end
Public Instance Methods
codes()
click to toggle source
Returns a collection of all available codes
This merges the STATUS_MAP
with specified codes
@return [Array] Collection of status codes
# File lib/nucleo/utilities/status_code_mapper.rb, line 27 def codes all_codes = [] @statuses.inject(all_codes) do |collection,status| if status.is_a?(Symbol) collection.concat(STATUS_MAP[status].to_a) else collection.concat([status.to_i]) end collection end Set.new(all_codes).to_a end
includes?(code)
click to toggle source
Checks to see if the codes includes a specific code
@param code [String,Integer] An HTTP code
@return [Boolean]
# File lib/nucleo/utilities/status_code_mapper.rb, line 47 def includes?(code) self.codes.include?(code.to_i) end