3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/spree/calculated_adjustments.rb', line 3
def calculated_adjustments(options = {})
has_one :calculator, :as => :calculable, :dependent => :destroy
accepts_nested_attributes_for :calculator
validates :calculator, :presence => true if options[:require]
class_attribute :calculators
self.calculators = Set.new
def register_calculator(calculator)
self.calculators.add(calculator)
end
if options[:default]
default_calculator_class = options[:default]
before_create :default_calculator
define_method(:default_calculator) do
self.calculator ||= default_calculator_class.new
end
else
define_method(:default_calculator) do
nil
end
end
include InstanceMethods
end
|