Sha256: 722fa622590cbccbc57783d2718690ce00001f98d8b97b1a552cd1d1661ae378

Contents?: true

Size: 940 Bytes

Versions: 34

Compression:

Stored size: 940 Bytes

Contents

module Workarea
  module Pricing
    class CacheKey
      attr_reader :shippings
      attr_accessor :order
      delegate :pricing, :discounts, to: :@request

      def initialize(order, shippings, request)
        @order = order
        @shippings = shippings
        @request = request
      end

      def parts
        [
          pricing_key,
          discount_key,
          order_key,
          shipping_service_key,
          tax_key
        ]
      end

      def to_s
        Digest::SHA1.hexdigest(parts.join('/'))
      end

      private

      def pricing_key
        pricing.map(&:cache_key).join
      end

      def discount_key
        discounts.map(&:cache_key).join
      end

      def order_key
        order.cache_key
      end

      def shipping_service_key
        shippings.map(&:cache_key).join
      end

      def tax_key
        Workarea::Tax::Category.all.map(&:cache_key).join
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
workarea-core-3.4.25 app/models/workarea/pricing/cache_key.rb
workarea-core-3.4.24 app/models/workarea/pricing/cache_key.rb
workarea-core-3.4.23 app/models/workarea/pricing/cache_key.rb
workarea-core-3.4.22 app/models/workarea/pricing/cache_key.rb
workarea-core-3.4.21 app/models/workarea/pricing/cache_key.rb
workarea-core-3.4.20 app/models/workarea/pricing/cache_key.rb
workarea-core-3.4.19 app/models/workarea/pricing/cache_key.rb
workarea-core-3.4.18 app/models/workarea/pricing/cache_key.rb
workarea-core-3.4.17 app/models/workarea/pricing/cache_key.rb
workarea-core-3.4.16 app/models/workarea/pricing/cache_key.rb
workarea-core-3.4.15 app/models/workarea/pricing/cache_key.rb
workarea-core-3.4.14 app/models/workarea/pricing/cache_key.rb
workarea-core-3.4.13 app/models/workarea/pricing/cache_key.rb
workarea-core-3.4.12 app/models/workarea/pricing/cache_key.rb