module DirtyHistory::Mixin::ObjectInstanceMethods
Public Instance Methods
add_dirty_history_record(column_name, old_value, new_value, options={})
click to toggle source
# File lib/dirty_history/dirty_history_mixin.rb, line 101 def add_dirty_history_record column_name, old_value, new_value, options={} creator = options[:creator] || self.creator_for_dirty_history dhr_attributes = { :object => self, :column_name => column_name, :column_type => self.class.columns_hash[column_name.to_s].type, :old_value => old_value, :new_value => new_value, :creator => creator } dhr = DirtyHistoryRecord.new(dhr_attributes) # attributes for manual updates [:revised_created_at, :performing_manual_update].each do |attribute| dhr.send("#{attribute}=", options[attribute]) if options[attribute] end self.dirty_history_records << dhr end
history_for_column(column, options={})
click to toggle source
# File lib/dirty_history/dirty_history_mixin.rb, line 123 def history_for_column column, options={} options[:sort] = true if options[:sort].blank? records = dirty_history_records.for_column(column) records = records.send(*options[:scope]) if options[:scope] records = records.order_asc if options[:sort] options[:return_objects] ? records : records.map { |s| s.new_value } end
save_dirty_history()
click to toggle source
# File lib/dirty_history/dirty_history_mixin.rb, line 89 def save_dirty_history return true unless self.dirty_history_changes.present? self.dirty_history_changes.each do |column_name,vals| add_dirty_history_record column_name, vals[0], vals[1], :creator => self.creator_for_dirty_history end self.dirty_history_changes = nil return true end
set_dirty_history_changes()
click to toggle source
# File lib/dirty_history/dirty_history_mixin.rb, line 76 def set_dirty_history_changes return true unless self.new_record? || self.changed? self.dirty_history_changes = self.class.dirty_history_columns.inject({}) do |changes_hash, column_name| changes_hash[column_name] = self.send("#{column_name}_change") if self.send("#{column_name}_changed?") changes_hash[column_name] ||= [nil, self.send(column_name)] if self.new_record? && self.send(column_name).present? changes_hash end self.initialize_dirty_history = self.new_record? return true end