Class: FaradayMiddleware::Mashify

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/faraday_middleware/response/mashify.rb

Overview

Public: Converts parsed response bodies to a Hashie::Mash if they were of Hash or Array type.

Direct Known Subclasses

Rashify

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app = nil, options = {}) ⇒ Mashify

Returns a new instance of Mashify.



20
21
22
23
# File 'lib/faraday_middleware/response/mashify.rb', line 20

def initialize(app = nil, options = {})
  super(app)
  self.mash_class = options[:mash_class] || self.class.mash_class
end

Class Attribute Details

.mash_classObject

Returns the value of attribute mash_class.



12
13
14
# File 'lib/faraday_middleware/response/mashify.rb', line 12

def mash_class
  @mash_class
end

Instance Attribute Details

#mash_classObject

Returns the value of attribute mash_class.



9
10
11
# File 'lib/faraday_middleware/response/mashify.rb', line 9

def mash_class
  @mash_class
end

Instance Method Details

#parse(body) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/faraday_middleware/response/mashify.rb', line 25

def parse(body)
  case body
  when Hash
    mash_class.new(body)
  when Array
    body.map { |item| parse(item) }
  else
    body
  end
end