Module: Dynamini::Adder

Included in:
Base
Defined in:
lib/dynamini/adder.rb

Constant Summary collapse

ADDABLE_TYPES =
[:set, :array, :integer, :float, :time, :date]

Instance Method Summary collapse

Instance Method Details

#add_to(attribute, value) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/dynamini/adder.rb', line 6

def add_to(attribute, value)
  complain_about(attribute) unless handles[attribute]
  old_value = read_attribute(attribute)
  add_value = attribute_callback(Dynamini::TypeHandler::SETTER_PROCS, handles[attribute], value)
  if ADDABLE_TYPES.include? handles[attribute][:format]
    @attributes[attribute] ? @attributes[attribute] += add_value : @attributes[attribute] = add_value
  else
    complain_about(attribute)
  end
  record_change(attribute, old_value, add_value, 'ADD')
  self
end