Module: Card::Dirty

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

Defined Under Namespace

Modules: MethodFactory

Instance Method Summary collapse

Methods included from MethodFactory

define_dirty_methods

Instance Method Details

#attribute_before_act(attr) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/card/dirty.rb', line 9

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
  end
end

#attribute_is_changing?(attr) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
32
33
# File 'lib/card/dirty.rb', line 26

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)


21
22
23
24
# File 'lib/card/dirty.rb', line 21

def not_in_callback?
  # or in integrate_with_delay stage
  mutations_before_last_save.equal?(mutations_from_database)
end