Sha256: 28d36703664dca062b97ce19a4cf7293996c271d1a8db9948db0d5d58f7142ce

Contents?: true

Size: 678 Bytes

Versions: 3

Compression:

Stored size: 678 Bytes

Contents

require 'fattr'
require 'forwardable'

module Leadlight
  class ConnectionBuilder
    extend Forwardable

    fattr(:url)
    fattr(:service)
    fattr(:common_stack)
    fattr(:adapter)

    def_delegators :service, :connection_stack, :logger

    def initialize
      yield self if block_given?
    end

    def call
      Faraday.new(url: url.to_s) do |connection|
        connection.use Leadlight::ServiceMiddleware, service: service
        connection.use Faraday::Response::Logger, logger
        service.instance_exec(connection, &connection_stack)
        service.instance_exec(connection, &common_stack)
        connection.adapter = adapter
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
leadlight-0.1.0 lib/leadlight/connection_builder.rb
leadlight-0.0.7 lib/leadlight/connection_builder.rb
leadlight-0.0.6 lib/leadlight/connection_builder.rb