Sha256: 44c4f2b742637d780d7c608b97cda44c192d5ce8858d80fa63cc8a81d0fe8013

Contents?: true

Size: 1.49 KB

Versions: 43

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true

module ErpIntegration
  module Fulfil
    # When making HTTP requests to the Fulfil API endpoints, it's possible to define
    # the warehouses that should be considered part of the querying context.
    #
    # This means that it's possible to fetch the stock levels for a specific "warehouse"
    # when it's specified in the context of the HTTP request to the API endpoints of
    # Fulfil.
    #
    # @example without any context, the main warehouse will be used as configured
    #           in Fulfil through the application settings.
    #
    #   $ ErpIntegration::Product.find_by(sku: "PT123").quantity_available
    #   => 25
    #
    # @example with context, the given warehouse will be used to find the requested
    #           data in Fulfil.
    #
    #   $ ErpIntegration::Product.with_context(locations: [25]).find_by(sku: "PT123").quantity_available
    #   => 15
    module Context
      extend ActiveSupport::Concern

      included do
        attr_accessor :context
      end

      # Verifies whether or not the context is set.
      #
      # @return [Boolean]
      def context?
        !@context.nil? && !@context.empty?
      end

      # Allows setting the context for the HTTP request to the Fulfil API endpoints.
      #
      # @param context [Hash] The context for the HTTP request.
      # @return [ErpIntegration::Fulfil::ApiResource]
      def with_context(context)
        @context = (@context || {}).merge(context)
        self
      end
    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
erp_integration-0.57.0 lib/erp_integration/fulfil/context.rb
erp_integration-0.56.0 lib/erp_integration/fulfil/context.rb
erp_integration-0.55.0 lib/erp_integration/fulfil/context.rb
erp_integration-0.54.0 lib/erp_integration/fulfil/context.rb
erp_integration-0.53.1 lib/erp_integration/fulfil/context.rb
erp_integration-0.53.0 lib/erp_integration/fulfil/context.rb
erp_integration-0.52.0 lib/erp_integration/fulfil/context.rb
erp_integration-0.50.0 lib/erp_integration/fulfil/context.rb
erp_integration-0.49.0 lib/erp_integration/fulfil/context.rb
erp_integration-0.48.0 lib/erp_integration/fulfil/context.rb
erp_integration-0.43.0 lib/erp_integration/fulfil/context.rb
erp_integration-0.42.0 lib/erp_integration/fulfil/context.rb
erp_integration-0.41.0 lib/erp_integration/fulfil/context.rb
erp_integration-0.40.0 lib/erp_integration/fulfil/context.rb
erp_integration-0.39.0 lib/erp_integration/fulfil/context.rb
erp_integration-0.38.0 lib/erp_integration/fulfil/context.rb
erp_integration-0.37.0 lib/erp_integration/fulfil/context.rb
erp_integration-0.36.1 lib/erp_integration/fulfil/context.rb
erp_integration-0.36.0 lib/erp_integration/fulfil/context.rb
erp_integration-0.35.0 lib/erp_integration/fulfil/context.rb