Sha256: 51441d4ef70fead644bbe8201759a1de2f98ee80476864a745f4628aa30b5ca9

Contents?: true

Size: 991 Bytes

Versions: 22

Compression:

Stored size: 991 Bytes

Contents

module Spree
  module CalculatedAdjustments
    extend ActiveSupport::Concern

    included do
      has_one :calculator, class_name: 'Spree::Calculator', as: :calculable, inverse_of: :calculable, dependent: :destroy, autosave: true
      accepts_nested_attributes_for :calculator
      validates :calculator, presence: true
      delegate :compute, to: :calculator

      def self.calculators
        spree_calculators.send model_name_without_spree_namespace
      end

      def calculator_type
        calculator.class.to_s if calculator
      end

      def calculator_type=(calculator_type)
        klass = calculator_type.constantize if calculator_type
        self.calculator = klass.new if klass && !calculator.instance_of?(klass)
      end

      private

      def self.model_name_without_spree_namespace
        to_s.tableize.tr('/', '_').sub('spree_', '')
      end

      def self.spree_calculators
        Rails.application.config.spree.calculators
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
spree_core-4.10.1 app/models/concerns/spree/calculated_adjustments.rb
spree_core-4.10.0 app/models/concerns/spree/calculated_adjustments.rb
spree_core-4.9.0 app/models/concerns/spree/calculated_adjustments.rb
spree_core-4.8.3 app/models/concerns/spree/calculated_adjustments.rb
spree_core-4.8.2 app/models/concerns/spree/calculated_adjustments.rb
spree_core-4.7.3 app/models/concerns/spree/calculated_adjustments.rb
spree_core-4.6.6 app/models/concerns/spree/calculated_adjustments.rb
spree_core-4.5.5 app/models/concerns/spree/calculated_adjustments.rb
spree_core-4.5.4 app/models/concerns/spree/calculated_adjustments.rb
spree_core-4.6.5 app/models/concerns/spree/calculated_adjustments.rb
spree_core-4.7.2 app/models/concerns/spree/calculated_adjustments.rb
spree_core-4.7.1 app/models/concerns/spree/calculated_adjustments.rb
spree_core-4.6.4 app/models/concerns/spree/calculated_adjustments.rb
spree_core-4.7.0 app/models/concerns/spree/calculated_adjustments.rb
spree_core-4.6.3 app/models/concerns/spree/calculated_adjustments.rb
spree_core-4.6.2 app/models/concerns/spree/calculated_adjustments.rb
spree_core-4.6.1 app/models/concerns/spree/calculated_adjustments.rb
spree_core-4.6.0 app/models/concerns/spree/calculated_adjustments.rb
spree_core-4.5.3 app/models/concerns/spree/calculated_adjustments.rb
spree_core-4.5.2 app/models/concerns/spree/calculated_adjustments.rb