Module: ChangeLogger::ActsAsChangeLogger::InstanceMethods

Defined in:
lib/change_logger/acts_as_change_logger.rb

Instance Method Summary collapse

Instance Method Details

#changes_to_trackObject



96
97
98
# File 'lib/change_logger/acts_as_change_logger.rb', line 96

def changes_to_track
  (new_record? ? attributes : changes).delete_if {|k,v| self.class.ignore.include?(k) }
end

#increment_revisionObject



41
42
43
# File 'lib/change_logger/acts_as_change_logger.rb', line 41

def increment_revision
  self.increment(:revision) if self.respond_to?(:revision)
end

#record_association_add(object) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/change_logger/acts_as_change_logger.rb', line 58

def record_association_add(object)
  # don't update individual adds if recording a template
  if self.class.track_templates.include?(object.class.to_s.tableize)
    self.template_changed = {} if self.template_changed.nil?
    self.template_changed[object.class.to_s.tableize.to_sym] = true          
  else
    record_change(object.class.to_s, ACTIONS[:create], object.id) if self.persisted?
  end
end

#record_association_remove(object) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/change_logger/acts_as_change_logger.rb', line 68

def record_association_remove(object)
  if self.class.track_templates.include?(object.class.to_s.tableize)
    self.template_changed = {} if self.template_changed.nil?
    self.template_changed[object.class.to_s.tableize.to_sym] = true          
  else
    record_change(object.class.to_s, object.id, ACTIONS[:delete]) if self.persisted?
  end
end

#record_attribute_updatesObject



83
84
85
86
87
88
# File 'lib/change_logger/acts_as_change_logger.rb', line 83

def record_attribute_updates
  changes_to_track.each do |key, value|
    ::ApplicationController::logger.info { "* #{key}, #{value[0]}, #{value[1]}"}
    record_change(key, value[0], value[1])
  end        
end

#record_object_creationObject



77
78
79
80
81
# File 'lib/change_logger/acts_as_change_logger.rb', line 77

def record_object_creation
  attributes.delete_if {|k,v| self.class.ignore.include?(k) }.each do |key, value|
    record_change(key, ACTIONS[:create], value) unless value.blank?
  end        
end

#record_object_destructionObject



90
91
92
93
94
# File 'lib/change_logger/acts_as_change_logger.rb', line 90

def record_object_destruction
  attributes.each do |key, value|
    record_change(key, value, ACTIONS[:delete])
  end
end

#record_template_changeObject



49
50
51
52
53
54
55
56
# File 'lib/change_logger/acts_as_change_logger.rb', line 49

def record_template_change
  return if self.template_changed.nil?
  # FIXME hash isn't necessary for self.template_changed, convert to using hash or remove need
  # for it altogether
  self.template_changed.keys.each do |relation|
    record_change("#{relation}_template", ACTIONS[:update], self.send(relation).to_yaml)
  end
end

#record_template_update(association) ⇒ Object



45
46
47
# File 'lib/change_logger/acts_as_change_logger.rb', line 45

def record_template_update(association)
  self.template_changed = {association.to_sym => true}
end