Class: CassandraObject::Savepoints::Rollback

Inherits:
Object
  • Object
show all
Defined in:
lib/cassandra_object/savepoints.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action, record) ⇒ Rollback

Returns a new instance of Rollback.



5
6
7
8
9
10
11
12
13
# File 'lib/cassandra_object/savepoints.rb', line 5

def initialize(action, record)
  @action = action
  @record = record
  if action == :update
    @rollback_attributes = record.changed_attributes.deep_dup
  elsif action == :create
    @rollback_attributes = record.attributes.deep_dup
  end
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



4
5
6
# File 'lib/cassandra_object/savepoints.rb', line 4

def action
  @action
end

#recordObject

Returns the value of attribute record.



4
5
6
# File 'lib/cassandra_object/savepoints.rb', line 4

def record
  @record
end

#rollback_attributesObject

Returns the value of attribute rollback_attributes.



4
5
6
# File 'lib/cassandra_object/savepoints.rb', line 4

def rollback_attributes
  @rollback_attributes
end

Instance Method Details

#run!Object



15
16
17
18
19
20
21
22
# File 'lib/cassandra_object/savepoints.rb', line 15

def run!
  case action
  when :destroy
    record.class.remove(record.id)
  when :create, :update
    record.class.write(record.id, rollback_attributes)
  end
end