Class: Faraday::Mashify::Middleware
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- Faraday::Mashify::Middleware
- Defined in:
- lib/faraday/mashify/middleware.rb
Overview
Public: Converts parsed response bodies to a Hashie::Mash if they were of Hash or Array type.
Class Attribute Summary collapse
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#initialize(app = nil, options = {}) ⇒ Middleware
constructor
A new instance of Middleware.
-
#on_complete(env) ⇒ Object
This method will be called when the response is being processed.
Constructor Details
#initialize(app = nil, options = {}) ⇒ Middleware
Returns a new instance of Middleware.
20 21 22 23 |
# File 'lib/faraday/mashify/middleware.rb', line 20 def initialize(app = nil, = {}) super(app, ) self.mash_class = [:mash_class] || self.class.mash_class || ::Hashie::Mash end |
Class Attribute Details
.mash_class ⇒ Class
14 15 16 |
# File 'lib/faraday/mashify/middleware.rb', line 14 def mash_class @mash_class end |
Instance Attribute Details
#mash_class ⇒ Class
9 10 11 |
# File 'lib/faraday/mashify/middleware.rb', line 9 def mash_class @mash_class end |
Instance Method Details
#on_complete(env) ⇒ Object
This method will be called when the response is being processed. You can alter it as you like, accessing things like response_body, response_headers, and more. Refer to Faraday::Env for a list of accessible fields: github.com/lostisland/faraday/blob/main/lib/faraday/options/env.rb
31 32 33 |
# File 'lib/faraday/mashify/middleware.rb', line 31 def on_complete(env) env[:body] = parse(env[:body]) end |