Class: Faraday::Response::ArrForce

Inherits:
Response::Middleware
  • Object
show all
Defined in:
lib/faraday/response/arr_force.rb

Instance Method Summary collapse

Constructor Details

#initialize(env = nil, *args) ⇒ ArrForce

Returns a new instance of ArrForce.



19
20
21
22
# File 'lib/faraday/response/arr_force.rb', line 19

def initialize(env = nil, *args)
  @to_array = [args.shift].flatten.map { |k| k.to_s }
  super(env)
end

Instance Method Details

#parse(body) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/faraday/response/arr_force.rb', line 6

def parse(body)
  return body unless @to_array.any?

  case body
  when Hash
    normalize(body)
  when Array
    body.map { |item| item.is_a?(Hash) ? normalize(item) : item }
  else
    body
  end
end