module ModelHistory::Mixin::ObjectInstanceMethods
Public Instance Methods
add_model_history_record(column_name, old_value, new_value, options={})
click to toggle source
# File lib/model_history/model_history_mixin.rb, line 97 def add_model_history_record column_name, old_value, new_value, options={} creator = options[:creator] || self.creator_for_model_history mhr_attributes = { :model => 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 = ModelHistoryRecord.new(mhr_attributes) # attributes for manual updates [:revised_created_at, :performing_manual_update].each do |attribute| dhr.send("#{attribute}=", options[attribute]) if options[attribute] end self.model_history_records << dhr end
history_for_column(column, options={})
click to toggle source
# File lib/model_history/model_history_mixin.rb, line 119 def history_for_column column, options={} options[:sort] = true if options[:sort].blank? records = model_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_model_history()
click to toggle source
# File lib/model_history/model_history_mixin.rb, line 88 def save_model_history return true unless self.model_history_changes.present? self.model_history_changes.each do |column_name,vals| add_model_history_record column_name, vals[0], vals[1], :creator => self.creator_for_model_history end self.model_history_changes = nil true end
set_model_history_changes()
click to toggle source
# File lib/model_history/model_history_mixin.rb, line 75 def set_model_history_changes return true unless self.new_record? || self.changed? self.model_history_changes = self.class.model_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_model_history = self.new_record? true end