module Dynamini::Dirty

Public Instance Methods

assign_transient_attribute(key, value) click to toggle source
# File lib/dynamini/dirty.rb, line 24
def assign_transient_attribute(key, value)
  write_attribute(key, value, change: :transient)
end
changed() click to toggle source
# File lib/dynamini/dirty.rb, line 9
def changed
  changes.keys.map(&:to_s)
end
changes() click to toggle source
# File lib/dynamini/dirty.rb, line 4
def changes
  @changes.delete_if { |attr, _value| keys.include?(attr) }
      .stringify_keys
end
mark(attr) click to toggle source
# File lib/dynamini/dirty.rb, line 17
def mark(attr)
  if @changes[attr][0..1] == [nil, nil]
    val = @attributes[attr]
    @changes[attr][0..1] = [val, val]
  end
end
new_record?() click to toggle source
# File lib/dynamini/dirty.rb, line 13
def new_record?
  @new_record
end

Private Instance Methods

__was(name) click to toggle source
# File lib/dynamini/dirty.rb, line 49
def __was(name)
  attr_name = name[0..-5].to_sym
  raise ArgumentError unless (@attributes[attr_name] || handles[attr_name])
  @changes[attr_name].compact.present? ? @changes[attr_name][0] : read_attribute(attr_name)
end
clear_change(attribute) click to toggle source
# File lib/dynamini/dirty.rb, line 35
def clear_change(attribute)
  @changes.delete(attribute)
end
clear_changes() click to toggle source
# File lib/dynamini/dirty.rb, line 39
def clear_changes
  @changes = Hash.new { |hash, key| hash[key] = Array.new(2) }
  @original_values = {}
end
record_change(attribute, old_value, new_value, action) click to toggle source
# File lib/dynamini/dirty.rb, line 30
def record_change(attribute, old_value, new_value, action)
  action ||= 'PUT'
  @changes[attribute] = [old_value, new_value, action]
end
was_method?(name) click to toggle source
# File lib/dynamini/dirty.rb, line 44
def was_method?(name)
  method_name = name.to_s
  read_method?(method_name) && method_name.end_with?('_was')
end