Class: Nucleo::Response
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Nucleo::Response
- Defined in:
- lib/nucleo/response.rb
Instance Method Summary collapse
-
#__getobj__ ⇒ Faraday::Response
Specify the class for Simple Delegator.
-
#allow_header ⇒ String
Extracts the ALLOW header from the HTTP Response.
-
#allowed?(method) ⇒ Boolean
Returns true if the method is allowed.
-
#allowed_methods ⇒ Array
Returns an array of allowed methods.
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
- #on(*statuses, &block) ⇒ Object
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
8 9 10 |
# File 'lib/nucleo/response.rb', line 8 def initialize(response) @_response = response end |
Instance Method Details
#__getobj__ ⇒ Faraday::Response
Specify the class for Simple Delegator
34 35 36 |
# File 'lib/nucleo/response.rb', line 34 def __getobj__ @_response end |
#allow_header ⇒ String
Extracts the ALLOW header from the HTTP Response
41 42 43 |
# File 'lib/nucleo/response.rb', line 41 def allow_header self.headers.fetch('allow', '') end |
#allowed?(method) ⇒ Boolean
Returns true if the method is allowed
15 16 17 |
# File 'lib/nucleo/response.rb', line 15 def allowed?(method) self.allowed_methods.include?(method.upcase) end |
#allowed_methods ⇒ Array
Returns an array of allowed methods
48 49 50 |
# File 'lib/nucleo/response.rb', line 48 def allowed_methods self.allow_header.split(',').map(&:strip).map(&:upcase) end |
#on(*statuses, &block) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/nucleo/response.rb', line 19 def on(*statuses, &block) status_code_mapper = Nucleo::Utilities::StatusCodeMapper.new(statuses) return unless status_code_mapper.includes?(@_response.status) if block_given? yield(self) and return else self end end |