Skip to content

Commit

Permalink
Making find_all work
Browse files Browse the repository at this point in the history
  • Loading branch information
German Otero committed Aug 30, 2011
1 parent 85cbacc commit 838c7c5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/cassandra_object/cursor.rb
@@ -1,10 +1,10 @@
module CassandraObject module CassandraObject
class Cursor class Cursor
def initialize(target_class, column_family, key, super_column, options={}) def initialize(target_class, column_family, key, super_column = nil, options={})
@target_class = target_class @target_class = target_class
@column_family = column_family @column_family = column_family
@key = key.to_s @key = key.to_s
@super_column = super_column @super_column = super_column if super_column
@options = options @options = options
@validators = [] @validators = []
end end
Expand Down
8 changes: 5 additions & 3 deletions lib/cassandra_object/indexes.rb
Expand Up @@ -45,19 +45,21 @@ class Index
def initialize(attribute_name, model_class, options) def initialize(attribute_name, model_class, options)
@attribute_name = attribute_name @attribute_name = attribute_name
@model_class = model_class @model_class = model_class
@reversed = options[:reversed] @reversed = false
@reversed = options[:reversed] if options[:reversed]

end end


def find(attribute_value, options = {}) def find(attribute_value, options = {})
cursor = CassandraObject::Cursor.new(@model_class, column_family, attribute_value.to_s, @attribute_name.to_s, :start_after=>options[:start_after], :reversed=>@reversed) cursor = CassandraObject::Cursor.new(@model_class, column_family, attribute_value.to_s, @attribute_name, :start_after=>options[:start_after], :reversed=>@reversed)
cursor.validator do |object| cursor.validator do |object|
object.send(@attribute_name) == attribute_value object.send(@attribute_name) == attribute_value
end end
cursor.find(options[:limit] || 100) cursor.find(options[:limit] || 100)
end end


def write(record) def write(record)
@model_class.connection.insert(column_family, record.send(@attribute_name).to_s, {@attribute_name.to_s=>record.key.to_s}) @model_class.connection.insert(column_family, record.send(@attribute_name).to_s, {@attribute_name.to_s=>{record.key.to_s => new_key}})
end end


def remove(record) def remove(record)
Expand Down
3 changes: 1 addition & 2 deletions lib/cassandra_object/persistence.rb
Expand Up @@ -62,8 +62,7 @@ def remove(key)


def all(keyrange = ''..'', options = {}) def all(keyrange = ''..'', options = {})
results = connection.get_range(column_family, :start => keyrange.first, :finish => keyrange.last, :count=>(options[:limit] || 100)) results = connection.get_range(column_family, :start => keyrange.first, :finish => keyrange.last, :count=>(options[:limit] || 100))
#keys = results.map(&:key) results.keys.map {|key| get(key) }
#keys.map {|key| get(key) }
end end


def first(keyrange = ''..'', options = {}) def first(keyrange = ''..'', options = {})
Expand Down

0 comments on commit 838c7c5

Please sign in to comment.