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



156
157
158
159
160
# File 'lib/cassandra_object/persistence.rb', line 156

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

#destroyed?Boolean

Returns:

  • (Boolean)


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

def destroyed?
  @destroyed
end

#new_record?Boolean

Returns:

  • (Boolean)


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

def new_record?
  @new_record
end

#persisted?Boolean

Returns:

  • (Boolean)


140
141
142
# File 'lib/cassandra_object/persistence.rb', line 140

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

#reload(options = nil) ⇒ Object



178
179
180
181
182
# File 'lib/cassandra_object/persistence.rb', line 178

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

#saveObject



144
145
146
147
148
149
150
# File 'lib/cassandra_object/persistence.rb', line 144

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

#save!Object



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

def save!
  create_or_update || raise(RecordNotSaved)
end

#update_attribute(name, value) ⇒ Object



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

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

#update_attributes(attributes) ⇒ Object



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

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

#update_attributes!(attributes) ⇒ Object



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

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