module Card::Dirty

Special “dirty” handling for significant card fields.

Public Class Methods

dirty_aliases() click to toggle source
# File lib/card/dirty.rb, line 11
def dirty_aliases
  { type: :type_id, content: :db_content }
end
dirty_fields() click to toggle source
# File lib/card/dirty.rb, line 7
def dirty_fields
  %i[name db_content trash type_id left_id right_id codename]
end
dirty_options() click to toggle source
# File lib/card/dirty.rb, line 15
def dirty_options
  dirty_fields + dirty_aliases.keys
end

Public Instance Methods

attribute_before_act(attr) click to toggle source
# File lib/card/dirty.rb, line 23
def attribute_before_act attr
  if saved_change_to_attribute? attr
    attribute_before_last_save attr
  elsif will_save_change_to_attribute? attr
    mutations_from_database.changed_values[attr]
  elsif not_in_callback?
    attribute_was attr
  else
    _read_attribute attr.to_s
  end
end
attribute_is_changing?(attr) click to toggle source
# File lib/card/dirty.rb, line 40
def attribute_is_changing? attr
  if not_in_callback?
    attribute_changed? attr
  else
    saved_change_to_attribute?(attr) ||
      will_save_change_to_attribute?(attr)
  end
end
not_in_callback?() click to toggle source
# File lib/card/dirty.rb, line 35
def not_in_callback?
  # or in integrate_with_delay stage
  mutations_before_last_save.equal?(mutations_from_database)
end