Sha256: 733845b5f521c0b9ce2247f1f33de2ddf243c91c6cfd9e0176b4bbfca7d1b962

Contents?: true

Size: 956 Bytes

Versions: 42

Compression:

Stored size: 956 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

      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

Version data entries

42 entries across 42 versions & 2 rubygems

Version Path
solidus_core-1.2.3 app/models/concerns/spree/calculated_adjustments.rb
solidus_core-1.1.4 app/models/concerns/spree/calculated_adjustments.rb
solidus_core-1.0.7 app/models/concerns/spree/calculated_adjustments.rb
solidus_core-1.0.6 app/models/concerns/spree/calculated_adjustments.rb
solidus_core-1.2.2 app/models/concerns/spree/calculated_adjustments.rb
solidus_core-1.2.1 app/models/concerns/spree/calculated_adjustments.rb
solidus_core-1.1.3 app/models/concerns/spree/calculated_adjustments.rb
solidus_core-1.0.5 app/models/concerns/spree/calculated_adjustments.rb
solidus_core-1.2.0 app/models/concerns/spree/calculated_adjustments.rb
solidus_core-1.2.0.rc2 app/models/concerns/spree/calculated_adjustments.rb
solidus_core-1.0.4 app/models/concerns/spree/calculated_adjustments.rb
solidus_core-1.1.2 app/models/concerns/spree/calculated_adjustments.rb
solidus_core-1.2.0.rc1 app/models/concerns/spree/calculated_adjustments.rb
solidus_core-1.2.0.beta1 app/models/concerns/spree/calculated_adjustments.rb
solidus_core-1.0.3 app/models/concerns/spree/calculated_adjustments.rb
solidus_core-1.1.1 app/models/concerns/spree/calculated_adjustments.rb
solidus_core-1.1.0 app/models/concerns/spree/calculated_adjustments.rb
solidus_core-1.1.0.pre2 app/models/concerns/spree/calculated_adjustments.rb
solidus_core-1.1.0.pre1 app/models/concerns/spree/calculated_adjustments.rb
solidus_core-1.1.0.beta1 app/models/concerns/spree/calculated_adjustments.rb