Module: Card::Dirty

Extended by:
MethodFactory
Included in:
Card
Defined in:
lib/card/dirty.rb,
lib/card/dirty/method_factory.rb

Overview

Special “dirty” handling for significant card fields.

Defined Under Namespace

Modules: MethodFactory

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MethodFactory

define_dirty_methods

Class Method Details

.dirty_aliasesObject



11
12
13
# File 'lib/card/dirty.rb', line 11

def dirty_aliases
  { type: :type_id, content: :db_content }
end

.dirty_fieldsObject



7
8
9
# File 'lib/card/dirty.rb', line 7

def dirty_fields
  %i[name db_content trash type_id left_id right_id codename]
end

.dirty_optionsObject



15
16
17
# File 'lib/card/dirty.rb', line 15

def dirty_options
  dirty_fields + dirty_aliases.keys
end

Instance Method Details

#attribute_before_act(attr) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# 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) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
43
44
45
46
47
# 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?Boolean

Returns:

  • (Boolean)


35
36
37
38
# 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