Class: FaradayMiddleware::Mashify
- Inherits:
-
Faraday::Response::Middleware
- Object
- Faraday::Response::Middleware
- FaradayMiddleware::Mashify
- 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
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.
18 19 20 21 |
# File 'lib/faraday_middleware/response/mashify.rb', line 18 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.
10 11 12 |
# File 'lib/faraday_middleware/response/mashify.rb', line 10 def mash_class @mash_class end |
Instance Attribute Details
#mash_class ⇒ Object
Returns the value of attribute mash_class.
7 8 9 |
# File 'lib/faraday_middleware/response/mashify.rb', line 7 def mash_class @mash_class end |
Instance Method Details
#parse(body) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/faraday_middleware/response/mashify.rb', line 23 def parse(body) case body when Hash mash_class.new(body) when Array body.map { |item| parse(item) } else body end end |