class CassandraRecord::Base
Attributes
attributes[RW]
Public Class Methods
batch_create(array_of_attributes, options={})
click to toggle source
# 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()
click to toggle source
# File lib/cassandra_record/base.rb, line 31 def configuration @@configuration ||= Configuration.new end
configure() { |configuration| ... }
click to toggle source
# File lib/cassandra_record/base.rb, line 27 def configure yield configuration end
create(attributes)
click to toggle source
# File lib/cassandra_record/base.rb, line 8 def create(attributes) new(attributes).create end
new(attributes={})
click to toggle source
# File lib/cassandra_record/base.rb, line 38 def initialize(attributes={}) @attributes = HashWithIndifferentAccess.new(attributes) end
where(attributes={})
click to toggle source
# File lib/cassandra_record/base.rb, line 23 def where(attributes={}) new.where(attributes) end
Public Instance Methods
create(options={})
click to toggle source
# File lib/cassandra_record/base.rb, line 48 def create(options={}) db.execute(insert_statement(attributes, options), *attributes.values) self end
where(options={})
click to toggle source
# 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
Private Instance Methods
db()
click to toggle source
# File lib/cassandra_record/base.rb, line 55 def db self.class.configuration.database_adapter end
insert_cql(attributes, options={})
click to toggle source
# File lib/cassandra_record/base.rb, line 67 def insert_cql(attributes, options={}) Statement.create(table_name, attributes.keys, attributes.values, options) end
insert_statement(attributes, options={})
click to toggle source
# File lib/cassandra_record/base.rb, line 63 def insert_statement(attributes, options={}) @insert_statement ||= db.prepare(insert_cql(attributes, options)) end
method_missing(method, *args, &block)
click to toggle source
Calls superclass method
# 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
table_name()
click to toggle source
# File lib/cassandra_record/base.rb, line 71 def table_name ActiveSupport::Inflector.tableize(self.class.name).gsub(/\//, '_') end
where_statement(options={})
click to toggle source
# File lib/cassandra_record/base.rb, line 59 def where_statement(options={}) Statement.where(table_name, options) end