Class: FaradayMiddleware::Mashify
- Inherits:
-
Faraday::Response::Middleware
- Object
- Faraday::Response::Middleware
- FaradayMiddleware::Mashify
- Defined in:
- lib/faraday/mashify.rb
Overview
Public: Converts parsed response bodies to a Hashie::Mash if they were of Hash or Array type.
Class Attribute Summary collapse
-
.mash_class ⇒ Object
Returns the value of attribute mash_class.
Instance Attribute Summary collapse
-
#mash_class ⇒ Object
Returns the value of attribute mash_class.
Instance Method Summary collapse
-
#initialize(app = nil, options = {}) ⇒ Mashify
constructor
A new instance of Mashify.
- #parse(body) ⇒ Object
Constructor Details
#initialize(app = nil, options = {}) ⇒ Mashify
Returns a new instance of Mashify.
20 21 22 23 |
# File 'lib/faraday/mashify.rb', line 20 def initialize(app = nil, = {}) super(app) self.mash_class = [:mash_class] || self.class.mash_class end |
Class Attribute Details
.mash_class ⇒ Object
Returns the value of attribute mash_class.
12 13 14 |
# File 'lib/faraday/mashify.rb', line 12 def mash_class @mash_class end |
Instance Attribute Details
#mash_class ⇒ Object
Returns the value of attribute mash_class.
9 10 11 |
# File 'lib/faraday/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/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 |