Class: Nucleo::Response

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/nucleo/response.rb

Instance Method Summary collapse

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

Returns:

  • (Faraday::Response)


34
35
36
# File 'lib/nucleo/response.rb', line 34

def __getobj__
  @_response
end

#allow_headerString

Extracts the ALLOW header from the HTTP Response

Returns:

  • (String)


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

Returns:

  • (Boolean)


15
16
17
# File 'lib/nucleo/response.rb', line 15

def allowed?(method)
  self.allowed_methods.include?(method.upcase)
end

#allowed_methodsArray

Returns an array of allowed methods

Returns:

  • (Array)


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