Sha256: f7f64fac812e89b37f51d5acb12b1ebe5bdd8f2faf7a19f23967605c5445a013

Contents?: true

Size: 789 Bytes

Versions: 15

Compression:

Stored size: 789 Bytes

Contents

# frozen_string_literal: true

module PriceHubble
  module EntityConcern
    # Allow entities to define their low level HTTP client to use.
    module Client
      extend ActiveSupport::Concern

      included do
        # The class constant of the low level client
        class_attribute :client_class

        # Get the cached low level client instance.
        #
        # @return [Mixed] the client instance
        def client
          @client ||= client_class.new
        end
      end

      class_methods do
        # Allows an entity to configure the client it depends on.
        #
        # @param name [Symbol, String] the client name, in snake_case
        def client(name)
          self.client_class = PriceHubble.client(name).class
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
pricehubble-1.3.0 lib/price_hubble/entity/concern/client.rb
pricehubble-1.2.5 lib/price_hubble/entity/concern/client.rb
pricehubble-1.2.4 lib/price_hubble/entity/concern/client.rb
pricehubble-1.2.3 lib/price_hubble/entity/concern/client.rb
pricehubble-1.2.2 lib/price_hubble/entity/concern/client.rb
pricehubble-1.2.1 lib/price_hubble/entity/concern/client.rb
pricehubble-1.2.0 lib/price_hubble/entity/concern/client.rb
pricehubble-1.1.0 lib/pricehubble/entity/concern/client.rb
pricehubble-1.0.0 lib/pricehubble/entity/concern/client.rb
pricehubble-0.4.2 lib/pricehubble/entity/concern/client.rb
pricehubble-0.4.1 lib/pricehubble/entity/concern/client.rb
pricehubble-0.4.0 lib/pricehubble/entity/concern/client.rb
pricehubble-0.3.0 lib/pricehubble/entity/concern/client.rb
pricehubble-0.2.0 lib/pricehubble/entity/concern/client.rb
pricehubble-0.1.0 lib/pricehubble/entity/concern/client.rb