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

#destroyObject



152
153
154
155
156
# File 'lib/cassandra_object/persistence.rb', line 152

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

#destroyed?Boolean

Returns:

  • (Boolean)


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

def destroyed?
  @destroyed
end

#new_record?Boolean

Returns:

  • (Boolean)


128
129
130
# File 'lib/cassandra_object/persistence.rb', line 128

def new_record?
  @new_record
end

#persisted?Boolean

Returns:

  • (Boolean)


136
137
138
# File 'lib/cassandra_object/persistence.rb', line 136

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

#reload(options = nil) ⇒ Object



174
175
176
177
178
# File 'lib/cassandra_object/persistence.rb', line 174

def reload(options = nil)
  clear_association_cache
  @attributes.update(self.class.find(self.id).instance_variable_get('@attributes'))
  self
end

#saveObject



140
141
142
143
144
145
146
# File 'lib/cassandra_object/persistence.rb', line 140

def save(*)
  begin
    create_or_update
  rescue CassandraObject::RecordInvalid
    false
  end
end

#save!Object



148
149
150
# File 'lib/cassandra_object/persistence.rb', line 148

def save!
  create_or_update || raise(RecordNotSaved)
end

#update_attribute(name, value) ⇒ Object



158
159
160
161
162
# File 'lib/cassandra_object/persistence.rb', line 158

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

#update_attributes(attributes) ⇒ Object



164
165
166
167
# File 'lib/cassandra_object/persistence.rb', line 164

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

#update_attributes!(attributes) ⇒ Object



169
170
171
172
# File 'lib/cassandra_object/persistence.rb', line 169

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