Module: Ripple::Document::Finders::ClassMethods
- Defined in:
- lib/ripple/document/finders.rb
Instance Method Summary collapse
-
#find(*args) ⇒ Object
Retrieve single or multiple documents from Riak.
-
#find!(*args) ⇒ Object
Retrieve single or multiple documents from Riak but raise Ripple::DocumentNotFound if a key can not be found in the bucket.
-
#first ⇒ Object
Find the first object using the first key in the bucket’s keys using find.
-
#first! ⇒ Object
Find the first object using the first key in the bucket’s keys using find!.
-
#list ⇒ Object
Find all documents in the Document’s bucket and return them.
Instance Method Details
#find(key) ⇒ Document #find(key1, key2, ...) ⇒ Array<Document> #find(keylist) ⇒ Array<Document>
Retrieve single or multiple documents from Riak.
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ripple/document/finders.rb', line 49 def find(*args) if args.first.is_a?(Array) args.flatten.map {|key| find_one(key) } else 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 end |
#find!(*args) ⇒ Object
Retrieve single or multiple documents from Riak but raise Ripple::DocumentNotFound if a key can not be found in the bucket.
63 64 65 66 67 |
# File 'lib/ripple/document/finders.rb', line 63 def find!(*args) found = find(*args) raise DocumentNotFound.new(args, found) if !found || Array(found).include?(nil) found end |
#first ⇒ Object
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.
73 74 75 |
# File 'lib/ripple/document/finders.rb', line 73 def first find(bucket.keys.first) end |
#first! ⇒ Object
Find the first object using the first key in the bucket’s keys using find!
79 80 81 |
# File 'lib/ripple/document/finders.rb', line 79 def first! find!(bucket.keys.first) end |
#list ⇒ Array<Document> #list {|Document| ... } ⇒ Object
This operation is incredibly expensive and should not be used in production applications.
Find all documents in the Document’s bucket and return them.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/ripple/document/finders.rb', line 94 def list 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 |