Module: Revisionable::ActiveRecord

Extended by:
ActiveSupport::Concern
Defined in:
lib/revisionable/active_record.rb

Instance Method Summary collapse

Instance Method Details

#update_attribute(name, value, options = {}) ⇒ Object

Overwrite this method. We want to create a new record when the current record is being updated



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/revisionable/active_record.rb', line 11

def update_attribute(name, value, options = {})
  options.reverse_merge!({:fork => true})
  
  if !options[:fork]
    return orig_update_attribute(name, value)
  else
    if child = self.childs.create({name => value})
      return child
    end
  end
  
  return false
end

#update_attributes(attributes) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/revisionable/active_record.rb', line 25

def update_attributes(attributes)
  attributes.reverse_merge!({:fork => true})
  
  if !attributes[:fork]
    # Remove the fork 'attributes' for the sake of AR
    attributes.delete(:fork)
    return super
  else
    attributes.delete_if {|k,| k == :fork}
    
    if child = self.childs.create(attributes)
      return child
    end
  end
  
  return false
end