Module: CassandraObject::Dirty

Extended by:
ActiveSupport::Concern
Includes:
ActiveModel::Dirty
Included in:
Base
Defined in:
lib/cassandra_object/dirty.rb

Instance Method Summary collapse

Instance Method Details

#saveObject

Attempts to save the record and clears changed attributes if successful.



7
8
9
10
11
12
13
14
# File 'lib/cassandra_object/dirty.rb', line 7

def save(*) #:nodoc:
  if status = super
    @previously_changed = changes
    @changed_attributes.clear
    @original_attribute_values = nil
  end
  status
end

#save!Object

Attempts to save! the record and clears changed attributes if successful.



17
18
19
20
21
22
23
# File 'lib/cassandra_object/dirty.rb', line 17

def save!(*) #:nodoc:
  super.tap do
    @previously_changed = changes
    @changed_attributes.clear
    @original_attribute_values = nil
  end
end

#write_attribute(name, value) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/cassandra_object/dirty.rb', line 25

def write_attribute(name, value)
  name = name.to_s

  # handle orig -> new -> orig
  if attribute_changed?(name)
    orig = changed_attributes[name]
    changed_attributes.delete(name) if orig == value
  else
    old = read_attribute(name)
    changed_attributes[name] = old if old != value
  end
  super
end