Module: CassandraObject::Persistence

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/cassandra_object/persistence.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#becomes(klass) ⇒ Object



123
124
125
126
127
128
129
# File 'lib/cassandra_object/persistence.rb', line 123

def becomes(klass)
  became = klass.new
  became.instance_variable_set("@attributes", @attributes)
  became.instance_variable_set("@new_record", new_record?)
  became.instance_variable_set("@destroyed", destroyed?)
  became
end

#destroyObject



102
103
104
105
# File 'lib/cassandra_object/persistence.rb', line 102

def destroy
  self.class.remove(id)
  @destroyed = true
end

#destroyed?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/cassandra_object/persistence.rb', line 90

def destroyed?
  @destroyed
end

#new_record?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/cassandra_object/persistence.rb', line 86

def new_record?
  @new_record
end

#persisted?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/cassandra_object/persistence.rb', line 94

def persisted?
  !(new_record? || destroyed?)
end

#reloadObject



131
132
133
134
135
# File 'lib/cassandra_object/persistence.rb', line 131

def reload
  clear_belongs_to_cache
  @attributes = self.class.find(id).instance_variable_get('@attributes')
  self
end

#saveObject



98
99
100
# File 'lib/cassandra_object/persistence.rb', line 98

def save(*)
  new_record? ? create : update
end

#update_attribute(name, value) ⇒ Object



107
108
109
110
111
# File 'lib/cassandra_object/persistence.rb', line 107

def update_attribute(name, value)
  name = name.to_s
  send("#{name}=", value)
  save(validate: false)
end

#update_attributes(attributes) ⇒ Object



113
114
115
116
# File 'lib/cassandra_object/persistence.rb', line 113

def update_attributes(attributes)
  self.attributes = attributes
  save
end

#update_attributes!(attributes) ⇒ Object



118
119
120
121
# File 'lib/cassandra_object/persistence.rb', line 118

def update_attributes!(attributes)
  self.attributes = attributes
  save!
end