Permalink
Browse files

Add Risky.keys

  • Loading branch information...
1 parent 2819b80 commit d5e063c2bc8c5d7098fe8a4c95599f3eef3aa902 Kyle Kingsbury committed May 4, 2011
Showing with 25 additions and 0 deletions.
  1. +18 −0 lib/risky.rb
  2. +7 −0 spec/enumerable.rb
View
@@ -132,6 +132,24 @@ def self.from_riak_object(riak_object)
def self.get_or_new(*args)
self[*args] or new(args.first)
end
+
+ # Iterate over all keys.
+ def self.keys(*a)
+ if block_given?
+ bucket.keys(*a) do |keys|
+ # This API is currently inconsistent from protobuffs to http
+ if keys.kind_of? Array
+ keys.each do |key|
+ yield key
+ end
+ else
+ yield keys
+ end
+ end
+ else
+ bucket.keys(*a)
+ end
+ end
# Establishes methods for manipulating a single link with a given tag.
def self.link(tag)
View
@@ -27,6 +27,13 @@ class Enum < Risky
Enum.count.should == 3
end
+ should 'list keys' do
+ Enum.keys.should.be.kind_of? Array
+ Enum.keys do |key|
+ key.should.be.kind_of? String
+ end
+ end
+
should 'each' do
seen = []
Enum.each do |obj|

0 comments on commit d5e063c

Please sign in to comment.