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



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

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

#destroyed?Boolean

Returns:

  • (Boolean)


122
123
124
# File 'lib/cassandra_object/persistence.rb', line 122

def destroyed?
  @destroyed
end

#new_record?Boolean

Returns:

  • (Boolean)


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

def new_record?
  @new_record
end

#persisted?Boolean

Returns:

  • (Boolean)


126
127
128
# File 'lib/cassandra_object/persistence.rb', line 126

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

#reload(options = nil) ⇒ Object



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

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

#saveObject



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

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

#save!Object



138
139
140
# File 'lib/cassandra_object/persistence.rb', line 138

def save!
  create_or_update || raise(RecordNotSaved)
end

#update_attribute(name, value) ⇒ Object



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

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

#update_attributes(attributes) ⇒ Object



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

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

#update_attributes!(attributes) ⇒ Object



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

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