Sha256: 179973f3cee1e0e3c50c666635186e08af0ca36dfda0b1a1017df61e940f12a1

Contents?: true

Size: 1.05 KB

Versions: 28

Compression:

Stored size: 1.05 KB

Contents

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

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

      def parts
        [
          pricing_key,
          discount_key,
          order_key,
          shipping_service_key,
          payment_key,
          tax_key
        ].compact
      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 payment_key
        payment&.cache_key
      end

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

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
workarea-core-3.5.27 app/models/workarea/pricing/cache_key.rb
workarea-core-3.5.26 app/models/workarea/pricing/cache_key.rb
workarea-core-3.5.25 app/models/workarea/pricing/cache_key.rb
workarea-core-3.5.23 app/models/workarea/pricing/cache_key.rb
workarea-core-3.5.22 app/models/workarea/pricing/cache_key.rb
workarea-core-3.5.21 app/models/workarea/pricing/cache_key.rb
workarea-core-3.5.20 app/models/workarea/pricing/cache_key.rb
workarea-core-3.5.19 app/models/workarea/pricing/cache_key.rb
workarea-core-3.5.18 app/models/workarea/pricing/cache_key.rb
workarea-core-3.5.17 app/models/workarea/pricing/cache_key.rb
workarea-core-3.5.16 app/models/workarea/pricing/cache_key.rb
workarea-core-3.5.15 app/models/workarea/pricing/cache_key.rb
workarea-core-3.5.14 app/models/workarea/pricing/cache_key.rb
workarea-core-3.5.13 app/models/workarea/pricing/cache_key.rb
workarea-core-3.5.12 app/models/workarea/pricing/cache_key.rb
workarea-core-3.5.11 app/models/workarea/pricing/cache_key.rb
workarea-core-3.5.10 app/models/workarea/pricing/cache_key.rb
workarea-core-3.5.9 app/models/workarea/pricing/cache_key.rb
workarea-core-3.5.8 app/models/workarea/pricing/cache_key.rb
workarea-core-3.5.7 app/models/workarea/pricing/cache_key.rb