Skip to content

Commit

Permalink
CouchtinyAdapter is added to the Xapit.
Browse files Browse the repository at this point in the history
ActiveRecord is commented out.
  • Loading branch information
opusmagnum committed Nov 9, 2010
1 parent 31b9340 commit cf20507
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
42 changes: 42 additions & 0 deletions lib/xapit/adapters/couchtiny_adapter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module Xapit
# This adapter is used for all CouchTiny::Document objects
class CouchtinyAdapter < AbstractAdapter
def self.for_class?(member_class)
#member_class.ancestors.map(&:to_s).include? "CouchTiny::Document"
member_class.ancestors.map(&:to_s).include? "MyCouchdbDocument"
end

# TODO override the rest of the methods here...
def find_single(id)
@target.get(id)
end

# Get multiple documents
def find_multiple(ids)
@target.all(:keys => ids)
end

# Use CouchRest pagination for batched find_each
def find_each(view = :all, query = {}, &block)
page = 1

# set batch size option
unless batch_size = query.delete(:batch_size)
batch_size = 200
end

begin
# Fetch one batch of records
collection = @target.view(view, query).paginate(
:page => page, :per_page => batch_size
)

collection.each do |record|
yield record
end

page += 1
end while not collection.empty?
end
end
end
6 changes: 3 additions & 3 deletions lib/xapit/index_blueprint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ def self.load_models
model_name = file.gsub(/^#{base}([\w_\/\\]+)\.rb/, '\1')

next if model_name.nil?
next if ::ActiveRecord::Base.send(:subclasses).detect { |model|
model.name == model_name
}
# next if ::ActiveRecord::Base.send(:subclasses).detect { |model|
# model.name == model_name
# }

begin
model_name.camelize.constantize
Expand Down

0 comments on commit cf20507

Please sign in to comment.