Module: Rollday::UseMiddleware
- Defined in:
- lib/rollday/use_middleware.rb
Class Method Summary collapse
- .register_middleware! ⇒ Object
-
.use_default_client_middleware! ⇒ Object
https://github.com/lostisland/faraday/issues/946#issuecomment-500607890 Monkey patch to force this middleware into every single Faraday.new client.
-
.use_default_middleware! ⇒ Object
https://github.com/lostisland/faraday/blob/816d824bc18453e86027c9c5fcf8427020566e50/lib/faraday/rack_builder.rb#L83-L86 https://github.com/lostisland/faraday/blob/816d824bc18453e86027c9c5fcf8427020566e50/lib/faraday/rack_builder.rb#L156-L169 Once the default middleware is crated and the Faraday Rack app has been built, it can not be removed from the middleware Faraday stack If removal is needed, then use the middleware per request instead of defaulted or use the
with_scopeto modify the parameters of the rollday gem.
Class Method Details
.register_middleware! ⇒ Object
33 34 35 36 37 38 |
# File 'lib/rollday/use_middleware.rb', line 33 def self.register_middleware! return false if @register_middleware ::Faraday::Middleware.register_middleware(Rollday::MIDDLEWARE_NAME => Middleware) @register_middleware = true end |
.use_default_client_middleware! ⇒ Object
https://github.com/lostisland/faraday/issues/946#issuecomment-500607890 Monkey patch to force this middleware into every single Faraday.new client
23 24 25 26 27 28 29 30 31 |
# File 'lib/rollday/use_middleware.rb', line 23 def self.use_default_client_middleware! return false if @use_default_client_middleware register_middleware! require "rollday/client_middleware" ::Faraday::ConnectionOptions.prepend(Rollday::FaradayConnectionOptions) @use_default_client_middleware = true end |
.use_default_middleware! ⇒ Object
https://github.com/lostisland/faraday/blob/816d824bc18453e86027c9c5fcf8427020566e50/lib/faraday/rack_builder.rb#L83-L86
https://github.com/lostisland/faraday/blob/816d824bc18453e86027c9c5fcf8427020566e50/lib/faraday/rack_builder.rb#L156-L169
Once the default middleware is crated and the Faraday Rack app has been built,
it can not be removed from the middleware Faraday stack
If removal is needed, then use the middleware per request instead of defaulted
or use the with_scope to modify the parameters of the rollday gem
11 12 13 14 15 16 17 18 19 |
# File 'lib/rollday/use_middleware.rb', line 11 def self.use_default_middleware! register_middleware! return false if @add_default_middleware idx = ::Faraday.default_connection.builder.handlers.size - 1 ::Faraday.default_connection.builder.insert(idx, Middleware) @add_default_middleware = true end |