# frozen_string_literal: true module ErpIntegration # Use the `Configuration` class to configure the ERP Integration gem. Use # an initializer in your project configure the ERP Integration gem. # # @example # ```ruby # # config/initializers/erp_integration.rb # ErpIntegration.configure do |config| # config.fulfil_api_key = "..." # end # ``` class Configuration # The `fulfil_api_key` is used by the `FulfilClient` to authorize the # requests to the Fulfil API endpoints. # @return [String] The API key for Fulfil. attr_accessor :fulfil_api_key # The `fulfil_merchant_id` is used by the `FulfilClient` to connect to # the right Fulfil API endpoints. # @return [String] The merchant ID for Fulfil. attr_accessor :fulfil_merchant_id # Allows configuring an adapter for the `SalesOrder` resource. When none is # configured, it will default to Fulfil. # @return [Symbol] The configured adapter for the sales orders attr_writer :sales_order_adapter # Allows configuring an adapter for the `SalesOrderLine` resource. When none is # configured, it will default to Fulfil. # @return [Symbol] The configured adapter for the order lines. attr_writer :sales_order_line_adapter # Allows configuring an adapter for the `Product` resource. When none is # configured, it will default to Fulfil. # @return [Symbol] The configured adapter for the products. attr_writer :product_adapter # Allows configuring an adapter for the `PurchaseOrder` resource. When none is # configured, it will default to Fulfil. # @return [Symbol] The configured adapter for the purchase orders. attr_writer :purchase_order_adapter # Allows configuring an adapter for the `PurchaseOrderLine` resource. When # none is configured, it will default to Fulfil. # @return [Symbol] The configured adapter for the purchase order lines. attr_writer :purchase_order_line_adapter # Allows configuring an adapter for the `PurchaseRequest` resource. When # none is configured, it will default to Fulfil. # @return [Symbol] The configured adapter for the purchase request. attr_writer :purchase_request_adapter def initialize(**options) options.each_pair do |key, value| public_send("#{key}=", value) if respond_to?("#{key}=") end end def sales_order_adapter @sales_order_adapter || :fulfil end def sales_order_line_adapter @sales_order_line_adapter || :fulfil end def product_adapter @product_adapter || :fulfil end def purchase_order_adapter @purchase_order_adapter || :fulfil end def purchase_order_line_adapter @purchase_order_line_adapter || :fulfil end def purchase_request_adapter @purchase_request_adapter || :fulfil end end # Returns ERP Integration's configuration. # @return [ErpIntegration::Configuration] ERP Integration's configuration def self.config @config ||= Configuration.new end # Allows setting a new configuration for the ERP Integration gem. # @return [ErpIntegration::Configuration] ERP Integration's new configuration def self.config=(configuration) raise BadConfiguration unless configuration.is_a?(Configuration) @config = configuration end # Allows modifying ERP Integration's configuration. # # @example # ErpIntegration.configure do |config| # config.some_api_key = "..." # end # def self.configure yield(config) end end