Sha256: 8011a0803e6f1a9cc614f989a0ae979da65d6ed8a9ccecba063a8f3eb0238c60

Contents?: true

Size: 783 Bytes

Versions: 3

Compression:

Stored size: 783 Bytes

Contents

# frozen_string_literal: true

module PriceHubble
  module Concern
    # 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

3 entries across 3 versions & 1 rubygems

Version Path
pricehubble-1.6.0 lib/price_hubble/entity/concern/client.rb
pricehubble-1.5.1 lib/price_hubble/entity/concern/client.rb
pricehubble-1.5.0 lib/price_hubble/entity/concern/client.rb