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



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

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



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

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

#destroyed?Boolean

Returns:

  • (Boolean)


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

def destroyed?
  @destroyed
end

#new_record?Boolean

Returns:

  • (Boolean)


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

def new_record?
  @new_record
end

#persisted?Boolean

Returns:

  • (Boolean)


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

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

#reloadObject



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

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

#saveObject



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

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

#update_attribute(name, value) ⇒ Object



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

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

#update_attributes(attributes) ⇒ Object



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

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

#update_attributes!(attributes) ⇒ Object



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

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