lib/riak/bucket.rb in ripple-0.6.0 vs lib/riak/bucket.rb in ripple-0.6.1
- old
+ new
@@ -16,10 +16,12 @@
module Riak
# Represents and encapsulates operations on a Riak 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::Escape
+
# @return [Riak::Client] the associated client
attr_reader :client
# @return [String] the bucket name
attr_reader :name
@@ -60,16 +62,16 @@
# @yield [Array<String>] a list of keys from the current chunk
# @option options [Boolean] :reload (false) If present, will force reloading of the bucket's keys from Riak
# @return [Array<String>] Keys in this bucket
def keys(options={})
if block_given?
- @client.http.get(200, @client.prefix, name, {:props => false}, {}) do |chunk|
+ @client.http.get(200, @client.prefix, escape(name), {:props => false}, {}) do |chunk|
obj = ActiveSupport::JSON.decode(chunk) rescue {}
yield obj['keys'].map {|k| URI.unescape(k) } if obj['keys']
end
elsif @keys.nil? || options[:reload]
- response = @client.http.get(200, @client.prefix, name, {:props => false}, {})
+ response = @client.http.get(200, @client.prefix, escape(name), {:props => false}, {})
load(response)
end
@keys
end
@@ -79,11 +81,11 @@
# @return [Hash] the properties that were accepted
# @raise [FailedRequest] if the new properties were not accepted by the Riak server
def props=(properties)
raise ArgumentError, t("hash_type", :hash => properties.inspect) unless Hash === properties
body = {'props' => properties}.to_json
- @client.http.put(204, @client.prefix, name, body, {"Content-Type" => "application/json"})
+ @client.http.put(204, @client.prefix, escape(name), body, {"Content-Type" => "application/json"})
@props = properties
end
# Retrieve an object from within the bucket.
# @param [String] key the key of the object to retrieve
@@ -91,11 +93,11 @@
# @option options [Fixnum] :r - the read quorum for the request - how many nodes should concur on the read
# @return [Riak::RObject] the object
# @raise [FailedRequest] if the object is not found or some other error occurs
def get(key, options={})
code = allow_mult ? [200,300] : 200
- response = @client.http.get(code, @client.prefix, name, key, options, {})
+ response = @client.http.get(code, @client.prefix, escape(name), escape(key), options, {})
RObject.new(self, key).load(response)
end
alias :[] :get
# Create a new blank object
@@ -124,11 +126,11 @@
# @return [true, false] whether the bucket allows divergent siblings
def allow_mult
props['allow_mult']
end
-
+
# Set the allow_mult property. *NOTE* This will result in a PUT request to Riak.
# @param [true, false] value whether the bucket should allow siblings
def allow_mult=(value)
self.props = props.merge('allow_mult' => value)
value
@@ -144,12 +146,12 @@
# @param [Fixnum] value the number of replicas the bucket should keep of each object
def n_value=(value)
self.props = props.merge('n_val' => value)
value
end
-
+
# @return [String] a representation suitable for IRB and debugging output
def inspect
- "#<Riak::Bucket #{client.http.path(client.prefix, name).to_s}#{" keys=[#{keys.join(',')}]" if defined?(@keys)}>"
+ "#<Riak::Bucket #{client.http.path(client.prefix, escape(name)).to_s}#{" keys=[#{keys.join(',')}]" if defined?(@keys)}>"
end
end
end