Class: Adjustment

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/adjustment.rb

Direct Known Subclasses

Charge, Credit

Instance Method Summary collapse

Instance Method Details

#amountObject



29
30
31
# File 'app/models/adjustment.rb', line 29

def amount
  read_attribute(:amount) || self.calculate_adjustment
end

#calculate_adjustmentObject



17
18
19
20
21
22
23
24
25
26
27
# File 'app/models/adjustment.rb', line 17

def calculate_adjustment
  if adjustment_source
    calc = adjustment_source.calculator || adjustment_source.default_calculator
    raise(RuntimeError, "#{self.class.name}##{id} doesn't have a calculator") unless calc
    calc.compute(adjustment_source)
  elsif read_attribute(:amount)
    read_attribute(:amount)
  else
    nil
  end
end

#update_amountObject



33
34
35
36
# File 'app/models/adjustment.rb', line 33

def update_amount
  new_amount = calculate_adjustment
  update_attribute(:amount, new_amount) if new_amount
end