forked from ryanb/xapit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CouchtinyAdapter is added to the Xapit.
ActiveRecord is commented out.
- Loading branch information
1 parent
31b9340
commit cf20507
Showing
2 changed files
with
45 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters