Sha256: 1eb05327db23e651d1e8625fb9dd62b288ba1babb024002a4369364c34ada02f

Contents?: true

Size: 1.06 KB

Versions: 14

Compression:

Stored size: 1.06 KB

Contents

module Spree
  module Core
    module CalculatedAdjustments
      def self.included(klass)
        klass.class_eval 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

          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 && !self.calculator.is_a?(klass)
          end

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

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

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
spree_core-2.3.13 lib/spree/core/calculated_adjustments.rb
spree_core-2.3.12 lib/spree/core/calculated_adjustments.rb
spree_core-2.3.11 lib/spree/core/calculated_adjustments.rb
spree_core-2.3.10 lib/spree/core/calculated_adjustments.rb
spree_core-2.3.9 lib/spree/core/calculated_adjustments.rb
spree_core-2.3.8 lib/spree/core/calculated_adjustments.rb
spree_core-2.3.7 lib/spree/core/calculated_adjustments.rb
spree_core-2.3.6 lib/spree/core/calculated_adjustments.rb
spree_core-2.3.5 lib/spree/core/calculated_adjustments.rb
spree_core-2.3.4 lib/spree/core/calculated_adjustments.rb
spree_core-2.3.3 lib/spree/core/calculated_adjustments.rb
spree_core-2.3.2 lib/spree/core/calculated_adjustments.rb
spree_core-2.3.1 lib/spree/core/calculated_adjustments.rb
spree_core-2.3.0 lib/spree/core/calculated_adjustments.rb