Class: Cql::Model
- Inherits:
-
Object
- Object
- Cql::Model
- Extended by:
- ActiveModel::Naming
- Includes:
- ActiveModel::Conversion, ActiveModel::Dirty, ActiveModel::Serialization, ActiveModel::Validations, FinderMethods, PersistenceMethods, SchemaMethods
- Defined in:
- lib/cql/model.rb,
lib/cql/model/version.rb
Defined Under Namespace
Modules: FinderMethods, PersistenceMethods, SchemaMethods Classes: QueryResult
Constant Summary collapse
- VERSION =
'0.0.5'
Instance Attribute Summary collapse
-
#primary_value ⇒ Object
readonly
Returns the value of attribute primary_value.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attributes = {}, options = {}) ⇒ Model
constructor
A new instance of Model.
- #persisted? ⇒ Boolean
- #quoted_primary_value ⇒ Object
Methods included from PersistenceMethods
Methods included from SchemaMethods
#consistency, #primary_key, #table_name
Constructor Details
#initialize(attributes = {}, options = {}) ⇒ Model
Returns a new instance of Model.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/cql/model.rb', line 33 def initialize(attributes = {}, = {}) self.class.columns.each do |key, config| class_eval do attr_reader config[:attribute_name] attr_writer config[:attribute_name] unless config[:read_only] end end @metadata = [:metadata] @primary_value = attributes[self.class.primary_key.to_sym] @persisted = false @deleted = false attributes.each do |key, value| attr_name = "@#{key.to_s}".to_sym instance_variable_set(attr_name, value) end self end |
Instance Attribute Details
#primary_value ⇒ Object (readonly)
Returns the value of attribute primary_value.
31 32 33 |
# File 'lib/cql/model.rb', line 31 def primary_value @primary_value end |
Class Method Details
.execute(query) ⇒ Object
62 63 64 65 |
# File 'lib/cql/model.rb', line 62 def self.execute(query) cql_results = Cql::Base.connection.execute(query, consistency) Cql::Model::QueryResult.new(cql_results, self) end |
Instance Method Details
#persisted? ⇒ Boolean
58 59 60 |
# File 'lib/cql/model.rb', line 58 def persisted? @persisted end |
#quoted_primary_value ⇒ Object
54 55 56 |
# File 'lib/cql/model.rb', line 54 def quoted_primary_value primary_value.is_a?(Fixnum) ? primary_value : "'#{primary_value}'" end |