Module: Ripple::Document::Finders::ClassMethods
- Defined in:
- ripple/lib/ripple/document/finders.rb
Instance Method Summary (collapse)
-
- (Object) all(options = {})
Find all documents in the Document’s bucket and return them.
-
- (Object) find(*args)
Retrieve single or multiple documents from Riak.
-
- (Object) find!(*args)
Retrieve single or multiple documents from Riak but raise Ripple::DocumentNotFound if a key can not be found in the bucket.
-
- (Object) first
Find the first object using the first key in the bucket’s keys using find.
-
- (Object) first!
Find the first object using the first key in the bucket’s keys using find!.
Instance Method Details
- (Array<Document>) all - (Object) all {|Document| ... }
Find all documents in the Document’s bucket and return them.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'ripple/lib/ripple/document/finders.rb', line 101 def all(={}) if block_given? bucket.keys do |keys| keys.each do |key| obj = find_one(key) yield obj if obj end end [] else bucket.keys().inject([]) do |acc, k| obj = find_one(k) obj ? acc << obj : acc end end end |
- (Document) find(key) - (Array<Document>) find(key1, key2, ...) - (Array<Document>) find(keylist)
Retrieve single or multiple documents from Riak.
62 63 64 65 66 67 |
# File 'ripple/lib/ripple/document/finders.rb', line 62 def find(*args) args.flatten! return nil if args.empty? || args.all?(&:blank?) return find_one(args.first) if args.size == 1 args.map {|key| find_one(key) } end |
- (Object) find!(*args)
Retrieve single or multiple documents from Riak but raise Ripple::DocumentNotFound if a key can not be found in the bucket.
72 73 74 75 76 |
# File 'ripple/lib/ripple/document/finders.rb', line 72 def find!(*args) found = find(*args) raise DocumentNotFound.new(args, found) if !found || Array(found).include?(nil) found end |
- (Object) first
Find the first object using the first key in the bucket’s keys using find. You should not expect to actually get the first object you added to the bucket. This is just a convenience method.
82 83 84 |
# File 'ripple/lib/ripple/document/finders.rb', line 82 def first find(bucket.keys.first) end |
- (Object) first!
Find the first object using the first key in the bucket’s keys using find!
88 89 90 |
# File 'ripple/lib/ripple/document/finders.rb', line 88 def first! find!(bucket.keys.first) end |