lib/riak/bucket.rb in riak-client-0.8.2 vs lib/riak/bucket.rb in riak-client-0.8.3

- old
+ new

@@ -39,14 +39,15 @@ # Used mostly internally - use {Riak::Client#bucket} to get a {Bucket} instance. # @param [Hash] response a response from {Riak::Client::HTTPBackend} # @return [Bucket] self # @see Client#bucket def load(response={}) - unless response.try(:[], :headers).try(:[],'content-type').try(:first) =~ /json$/ + content_type = response[:headers]['content-type'].first rescue "" + unless content_type =~ /json$/ raise Riak::InvalidResponse.new({"content-type" => ["application/json"]}, response[:headers], t("loading_bucket", :name => name)) end - payload = ActiveSupport::JSON.decode(response[:body]) + payload = JSON.parse(response[:body]) @keys = payload['keys'].map {|k| CGI.unescape(k) } if payload['keys'] @props = payload['props'] if payload['props'] self end @@ -59,11 +60,12 @@ # @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, escape(name), {:props => false, :keys => 'stream'}, {}) do |chunk| - obj = ActiveSupport::JSON.decode(chunk) rescue {} + obj = JSON.parse(chunk) rescue nil + next unless obj and obj['keys'] yield obj['keys'].map {|k| CGI.unescape(k) } if obj['keys'] end elsif @keys.nil? || options[:reload] response = @client.http.get(200, @client.prefix, escape(name), {:props => false, :keys => true}, {}) load(response) @@ -95,16 +97,17 @@ raise ArgumentError, t("hash_type", :hash => properties.inspect) unless Hash === properties body = {'props' => properties}.to_json @client.http.put(204, @client.prefix, escape(name), body, {"Content-Type" => "application/json"}) @props.merge!(properties) end + alias properties= props= # @return [Hash] Internal Riak bucket properties. # @see #props= def props @props end - alias_attribute :properties, :props + alias properties props # Retrieve an object from within the bucket. # @param [String] key the key of the object to retrieve # @param [Hash] options query parameters for the request # @option options [Fixnum] :r - the read quorum for the request - how many nodes should concur on the read