Class: Johac::Connection::Middleware::PersistentAdapter

Inherits:
Faraday::Adapter::NetHttpPersistent
  • Object
show all
Defined in:
lib/johac/connection.rb

Overview

Wrapper of Faraday::Adapter::NetHttpPersistent adapter that allows for a block to be given when the faraday connection is created. Block is passed the newly created Net::HTTP::Persistent instance to be modified if desired.

Allows for configuration of HTTP connection.

Instance Method Summary collapse

Constructor Details

#initialize(app) {|Net::HTTP::Persistent| ... } ⇒ PersistentAdapter

Extend Faraday::Adapter::NetHttpPersistent’s initialize method with an optional block.

Yields:

  • (Net::HTTP::Persistent)

    Stores the passed block for use when creating a new HTTP connection.



87
88
89
90
# File 'lib/johac/connection.rb', line 87

def initialize(app, &block)
  @config_block = block
  super(app)
end

Instance Method Details

#with_net_http_connection(env) {|http| ... } ⇒ Object

Yield HTTP connection to supplied block.

Yields:

  • (http)


93
94
95
96
97
# File 'lib/johac/connection.rb', line 93

def with_net_http_connection(env, &block)
  http = super(env) { |v| v }
  @config_block.call(http) if @config_block
  yield http
end