Module: ActiveRecord::Deltas
- Included in:
- Base
- Defined in:
- lib/ar-deltas.rb
Class Method Summary collapse
Instance Method Summary collapse
- #attributes_with_quotes_with_deltas(*args) ⇒ Object
- #excluded_deltas ⇒ Object
- #force_clobber(attr_name, value) ⇒ Object
Class Method Details
.included(klass) ⇒ Object
4 5 6 7 8 |
# File 'lib/ar-deltas.rb', line 4 def self.included(klass) klass.class_eval do alias_method_chain :attributes_with_quotes, :deltas end end |
Instance Method Details
#attributes_with_quotes_with_deltas(*args) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ar-deltas.rb', line 10 def attributes_with_quotes_with_deltas(*args) with_deltas = attributes_with_quotes_without_deltas(*args) return with_deltas if self.new_record? with_deltas.keys.each do |attribute_name| if self.class.delta_attributes.include?(attribute_name.intern) && !self.excluded_deltas.include?(attribute_name.intern) delta_string = "#{self.connection.quote_column_name(attribute_name)} " old_value, new_value = self.changes[attribute_name] delta_string << (old_value > new_value ? "-" : "+") delta_string << " #{(old_value - new_value).abs}" with_deltas[attribute_name] = delta_string end end with_deltas end |
#excluded_deltas ⇒ Object
25 26 27 |
# File 'lib/ar-deltas.rb', line 25 def excluded_deltas @_excluded_deltas ||= Set.new end |
#force_clobber(attr_name, value) ⇒ Object
29 30 31 32 |
# File 'lib/ar-deltas.rb', line 29 def force_clobber(attr_name, value) self.excluded_deltas.add(attr_name.to_s.intern) send("#{attr_name}=", value) end |