Module: Cql::Model::InstanceMethods
- Defined in:
- lib/cql/model/instance_methods.rb
Instance Method Summary collapse
-
#[](name) ⇒ Object
Read a property.
-
#initialize(cql_properties = nil) ⇒ Object
Instantiate a new instance of this model.
-
#update(values = {}) ⇒ Cql::Model::Query::InsertStatement
Start an INSERT CQL statement to update model.
-
#update_all_by(key, values = {}) ⇒ Cql::Model::Query::UpdateStatement
Start an UPDATE CQL statement to update all models with given key This can update multiple models if the key is part of a composite key Updating all models with given (different) key values can be done using the ‘.update’ class method.
Instance Method Details
#[](name) ⇒ Object
Read a property. Property names are column names, and can therefore take any data type that a column name can take (integer, UUID, etc).
16 17 18 |
# File 'lib/cql/model/instance_methods.rb', line 16 def [](name) @cql_properties[name] end |
#initialize(cql_properties = nil) ⇒ Object
Instantiate a new instance of this model. Do not validate the contents of cql_properties; it may contain properties that aren’t declared by this model, that have a missing CQL column, or an improper name/value for their column type.
7 8 9 |
# File 'lib/cql/model/instance_methods.rb', line 7 def initialize(cql_properties=nil) @cql_properties = cql_properties || {} end |
#update(values = {}) ⇒ Cql::Model::Query::InsertStatement
Start an INSERT CQL statement to update model
30 31 32 33 |
# File 'lib/cql/model/instance_methods.rb', line 30 def update(values={}) key_vals = self.class.primary_key.inject({}) { |h, k| h[k] = @cql_properties[k]; h } Cql::Model::Query::UpdateStatement.new(self.class).update(values.merge(key_vals)) end |
#update_all_by(key, values = {}) ⇒ Cql::Model::Query::UpdateStatement
Start an UPDATE CQL statement to update all models with given key This can update multiple models if the key is part of a composite key Updating all models with given (different) key values can be done using the ‘.update’ class method
47 48 49 |
# File 'lib/cql/model/instance_methods.rb', line 47 def update_all_by(key, values={}) Cql::Model::Query::UpdateStatement.new(self.class).update(values.merge({ key => @cql_properties[key.to_s] })) end |