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
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module CassandraObject
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
@column_family = column_family
@key = key.to_s
@super_column = super_column
@super_column = super_column if super_column
@options = options
@validators = []
end
Expand Down
8 changes: 5 additions & 3 deletions lib/cassandra_object/indexes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,21 @@ class Index
def initialize(attribute_name, model_class, options)
@attribute_name = attribute_name
@model_class = model_class
@reversed = options[:reversed]
@reversed = false
@reversed = options[:reversed] if options[:reversed]

end

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|
object.send(@attribute_name) == attribute_value
end
cursor.find(options[:limit] || 100)
end

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

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

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

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

0 comments on commit 838c7c5

Please sign in to comment.