lib/riak/robject.rb in ripple-0.6.0 vs lib/riak/robject.rb in ripple-0.6.1

- old
+ new

@@ -18,10 +18,11 @@ # Parent class of all object types supported by ripple. {Riak::RObject} represents # the data and metadata stored in a bucket/key pair in the Riak database. class RObject include Util include Util::Translation + include Util::Escape # @return [Bucket] the bucket in which this object is contained attr_accessor :bucket # @return [String] the key of this object within its bucket @@ -115,11 +116,11 @@ # @return [Riak::RObject] self # @raise [ArgumentError] if the content_type is not defined def store(options={}) raise ArgumentError, t("content_type_undefined") unless @content_type.present? params = {:returnbody => true}.merge(options) - method, codes, path = @key.present? ? [:put, [200,204], "#{@bucket.name}/#{@key}"] : [:post, 201, @bucket.name] + method, codes, path = @key.present? ? [:put, [200,204,300], "#{escape(@bucket.name)}/#{escape(@key)}"] : [:post, 201, escape(@bucket.name)] response = @bucket.client.http.send(method, codes, @bucket.client.prefix, path, params, serialize(data), store_headers) load(response) end # Reload the object from Riak. Will use conditional GETs when possible. @@ -129,22 +130,22 @@ # @return [Riak::RObject] self def reload(options={}) force = options.delete(:force) return self unless @key && (@vclock || force) codes = @bucket.allow_mult ? [200,300,304] : [200,304] - response = @bucket.client.http.get(codes, @bucket.client.prefix, @bucket.name, @key, options, reload_headers) + response = @bucket.client.http.get(codes, @bucket.client.prefix, escape(@bucket.name), escape(@key), options, reload_headers) load(response) unless response[:code] == 304 self end alias :fetch :reload # Delete the object from Riak and freeze this instance. Will work whether or not the object actually # exists in the Riak database. def delete return if key.blank? - @bucket.client.http.delete([204,404], @bucket.client.prefix, @bucket.name, key) + @bucket.client.http.delete([204,404], @bucket.client.prefix, escape(@bucket.name), escape(@key)) freeze end # Returns sibling objects when in conflict. # @return [Array<RObject>] an array of conflicting sibling objects for this key @@ -213,17 +214,17 @@ end end # @return [String] A representation suitable for IRB and debugging output def inspect - "#<#{self.class.name} #{@bucket.client.http.path(@bucket.client.prefix, @bucket.name, @key).to_s} [#{@content_type}]:#{@data.inspect}>" + "#<#{self.class.name} #{@bucket.client.http.path(@bucket.client.prefix, escape(@bucket.name), escape(@key)).to_s} [#{@content_type}]:#{@data.inspect}>" end # Walks links from this object to other objects in Riak. def walk(*params) specs = WalkSpec.normalize(*params) - response = @bucket.client.http.get(200, @bucket.client.prefix, @bucket.name, @key, specs.join("/")) + response = @bucket.client.http.get(200, @bucket.client.prefix, escape(@bucket.name), escape(@key), specs.join("/")) if boundary = Multipart.extract_boundary(response[:headers]['content-type'].first) Multipart.parse(response[:body], boundary).map do |group| map_walk_group(group) end else @@ -231,10 +232,10 @@ end end # Converts the object to a link suitable for linking other objects to it def to_link(tag=nil) - Link.new(@bucket.client.http.path(@bucket.client.prefix, @bucket.name, @key).path, tag) + Link.new(@bucket.client.http.path(@bucket.client.prefix, escape(@bucket.name), escape(@key)).path, tag) end private def extract_header(response, name, attribute=nil) if response[:headers][name].present?