Class: CassandraRecord::Base
- Inherits:
-
Object
- Object
- CassandraRecord::Base
show all
- Defined in:
- lib/cassandra_record/base.rb
Defined Under Namespace
Classes: Configuration
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(attributes = {}) ⇒ Base
Returns a new instance of Base.
38
39
40
|
# File 'lib/cassandra_record/base.rb', line 38
def initialize(attributes={})
@attributes = HashWithIndifferentAccess.new(attributes)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
75
76
77
78
79
80
81
|
# File 'lib/cassandra_record/base.rb', line 75
def method_missing(method, *args, &block)
if attributes.has_key?(method)
attributes[method]
else
super(method, *args, &block)
end
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
36
37
38
|
# File 'lib/cassandra_record/base.rb', line 36
def attributes
@attributes
end
|
Class Method Details
.batch_create(array_of_attributes, options = {}) ⇒ Object
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/cassandra_record/base.rb', line 12
def batch_create(array_of_attributes, options={})
batch = configuration.database_adapter.session.batch do |batch|
array_of_attributes.map do |attr|
batch.add(new(attr).send(:insert_statement, attr, options), attr.values)
end
end
configuration.database_adapter.session.execute(batch)
array_of_attributes.map { |attr| new(attr) }
end
|
.configuration ⇒ Object
31
32
33
|
# File 'lib/cassandra_record/base.rb', line 31
def configuration
@@configuration ||= Configuration.new
end
|
27
28
29
|
# File 'lib/cassandra_record/base.rb', line 27
def configure
yield configuration
end
|
.create(attributes) ⇒ Object
8
9
10
|
# File 'lib/cassandra_record/base.rb', line 8
def create(attributes)
new(attributes).create
end
|
.where(attributes = {}) ⇒ Object
23
24
25
|
# File 'lib/cassandra_record/base.rb', line 23
def where(attributes={})
new.where(attributes)
end
|
Instance Method Details
#create(options = {}) ⇒ Object
48
49
50
51
|
# File 'lib/cassandra_record/base.rb', line 48
def create(options={})
db.execute(insert_statement(attributes, options), *attributes.values)
self
end
|
#where(options = {}) ⇒ Object
42
43
44
45
46
|
# File 'lib/cassandra_record/base.rb', line 42
def where(options={})
db.execute(where_statement(options)).map do |attributes|
self.class.new(attributes)
end
end
|