Sha256: 8c86eeaa924bf9dd28827c747922a3ad7b2e4ff85ae5a0c704f9ebd3cb206b9a
Contents?: true
Size: 943 Bytes
Versions: 21
Compression:
Stored size: 943 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 end class_methods do def calculators spree_calculators.send model_name_without_spree_namespace end private def model_name_without_spree_namespace to_s.tableize.tr('/', '_').sub('spree_', '') end def spree_calculators Rails.application.config.spree.calculators end 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.is_a?(klass) end end end
Version data entries
21 entries across 21 versions & 1 rubygems