lib/riak/bucket.rb in riakpb-0.1.6 vs lib/riak/bucket.rb in riakpb-0.2.0
- old
+ new
@@ -1,15 +1,15 @@
require 'riak'
-module Riak
- # Represents and encapsulates operations on a Riak bucket. You may retrieve a bucket
+module Riakpb
+ # Represents and encapsulates operations on a Riakpb bucket. You may retrieve a bucket
# using {Client#bucket}, or create it manually and retrieve its meta-information later.
class Bucket
include Util::Translation
include Util::MessageCode
- # @return [Riak::Client] the associated client
+ # @return [Riakpb::Client] the associated client
attr_reader :client
# @return [String] the bucket name
attr_reader :name
@@ -19,32 +19,32 @@
# @return [TrueClass/FalseClass] whether or not a key's siblings are to be retrieved
attr_reader :allow_mult
attr_reader :key_cache
- # Create a Riak bucket manually.
- # @param [Client] client the {Riak::Client} for this bucket
+ # Create a Riakpb bucket manually.
+ # @param [Client] client the {Riakpb::Client} for this bucket
# @param [String] name the name of the bucket
def initialize(client, name, options={})
- options.assert_valid_keys(:n_val, :allow_mult)
+ options.assert_valid_keys(:n_val, :allow_mult, :return_body)
raise ArgumentError, t("client_type", :client => client.inspect) unless client.is_a?(Client)
raise ArgumentError, t("string_type", :string => name.inspect) unless name.is_a?(String)
@client = client
@name = name
self.n_val ||= options[:n_val]
self.allow_mult ||= options[:allow_mult]
- @key_cache = Hash.new{|k,v| k[v] = Riak::Key.new(self, v)}
+ @key_cache = Hash.new{|k,v| k[v] = Riakpb::Key.new(self, v)}
end
- # Load information for the bucket from a response given by the {Riak::Client::HTTPBackend}.
- # Used mostly internally - use {Riak::Client#bucket} to get a {Bucket} instance.
- # @param [RpbHash] response a response from {Riak::Client::HTTPBackend}
+ # Load information for the bucket from a response given by the {Riakpb::Client::HTTPBackend}.
+ # Used mostly internally - use {Riakpb::Client#bucket} to get a {Bucket} instance.
+ # @param [RpbHash] response a response from {Riakpb::Client::HTTPBackend}
# @return [Bucket] self
# @see Client#bucket
def load(response)
- if response.is_a?(Riak::RpbGetBucketResp)
+ if response.is_a?(Riakpb::RpbGetBucketResp)
@n_val = response.props.n_val
@allow_mult = response.props.allow_mult
return(self)
end
@@ -64,11 +64,11 @@
end
# Retrieve an object from within the bucket.
# @param [String] key the key of the object to retrieve
# @param [Fixnum] r - the read quorum for the request - how many nodes should concur on the read
- # @return [Riak::Key] the object
+ # @return [Riakpb::Key] the object
def key(key, options={})
raise ArgumentError, t("fixnum_invalid", :num => options[:r]) unless options[:r].is_a?(NilClass) or options[:r].is_a?(Fixnum)
raise ArgumentError, t("string_invalid", :string => key) unless key.is_a?(String)
if options[:safely] == true and not @key_cache[key].empty?
@@ -82,25 +82,25 @@
alias :[] :key
# Retrieve an object from within the bucket. Will raise an error message if key does not exist.
# @param [String] key the key of the object to retrieve
# @param [Fixnum] quorum - the read quorum for the request - how many nodes should concur on the read
- # @return [Riak::Key] the object
+ # @return [Riakpb::Key] the object
def key!(key, r=nil)
raise ArgumentError, t("string_invalid", :string => key) unless key.is_a?(String)
raise ArgumentError, t("fixnum_invalid", :num => r) unless r.is_a?(Fixnum) or r.nil?
response = @client.get_request @name, key, r
- Riak::Key.new(self, key).load!(response)
+ Riakpb::Key.new(self, key).load!(response)
end
# Retrieves a Key from the given Bucket. Originally written for link retrieval.
# @param [String] bucket the name of the bucket, in which the Key is contained
# @param [String] key the name of the key to retrieve
# @option options [Fixnum] :quorum read quorum- num of replicas need to agree when retrieving the object
- # @return [Riak::Key] the object
+ # @return [Riakpb::Key] the object
def get_linked(bucket, key, options=nil)
@client[bucket].key(key, options)
end
# Retrieves a Key from the given Bucket. Originally written for link retrieval.
@@ -121,23 +121,23 @@
params[:usermeta] = parse_links(params[:usermeta]) if params.has_key?(:usermeta)
options = params.slice :return_body, :w, :dw
content = params.slice :value, :content_type, :charset, :content_encoding, :links, :usermeta
- key = key.name if key.is_a?(Riak::Key)
+ key = key.name if key.is_a?(Riakpb::Key)
options[:key] = key
- options[:content] = Riak::RpbContent.new(content)
+ options[:content] = Riakpb::RpbContent.new(content)
self.store(options)
end
# Deletes a key from the bucket
# @param [String] key the key to delete
# @param [Hash] options quorum options
# @option options [Fixnum] :rw - the read/write quorum for the delete
def delete(key, rw=nil)
- key = key.name if key.is_a?(Riak::Key)
+ key = key.name if key.is_a?(Riakpb::Key)
@client.del_request(@name, key, rw)
end
# Wipes out all keys stored in the bucket, as of execution
@@ -156,11 +156,11 @@
# @return [true, false] whether the bucket allows divergent siblings
def allow_mult
@allow_mult
end
- # Set the allow_mult property. *NOTE* This will result in a PUT request to Riak.
+ # Set the allow_mult property. *NOTE* This will result in a PUT request to Riakpb.
# @param [true, false] value whether the bucket should allow siblings
def allow_mult=(value)
case value
when true, false
@client.set_bucket(self.name, {:n_val => @n_val, :allow_mult => value})
@@ -192,24 +192,24 @@
end
end
# @return [String] a representation suitable for IRB and debugging output
def inspect
- "#<Riak::Bucket name=#{@name}, props={n_val=>#{@n_val}, allow_mult=#{@allow_mult}}>"
+ "#<Riakpb::Bucket name=#{@name}, props={n_val=>#{@n_val}, allow_mult=#{@allow_mult}}>"
end
# @return [String] a representation suitable for IRB and debugging output, including keys within this bucket
def inspect!
- "#<Riak::Bucket name=#{@name}, props={n_val=>#{@n_val}, allow_mult=#{@allow_mult}}, keys=#{keys.inspect}>"
+ "#<Riakpb::Bucket name=#{@name}, props={n_val=>#{@n_val}, allow_mult=#{@allow_mult}}, keys=#{keys.inspect}>"
end
private
def parse_links(link_params)
rpb_links = []
link_params.each do |tag, links|
- pb_link = Riak::RpbLink.new
+ pb_link = Riakpb::RpbLink.new
pb_link.tag = tag
pb_link.bucket = links[0]
pb_link.key = links[1]
rpb_links << pb_link
end
@@ -218,10 +218,10 @@
def parse_meta(meta_params)
rpb_meta = []
meta_params.each do |k,v|
- pb_meta = Riak::RpbPair.new
+ pb_meta = Riakpb::RpbPair.new
pb_meta.key = k
pb_meta.value = v
rpb_meta << pb_meta
end
return(rpb_meta)