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



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

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



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

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

#destroyed?Boolean

Returns:

  • (Boolean)


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

def destroyed?
  @destroyed
end

#new_record?Boolean

Returns:

  • (Boolean)


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

def new_record?
  @new_record
end

#persisted?Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/cassandra_object/persistence.rb', line 111

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

#reloadObject



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

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

#saveObject



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

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

#update_attribute(name, value) ⇒ Object



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

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

#update_attributes(attributes) ⇒ Object



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

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

#update_attributes!(attributes) ⇒ Object



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

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