lib/riak/client/http_backend/object_methods.rb in riak-client-0.9.8 vs lib/riak/client/http_backend/object_methods.rb in riak-client-1.0.0.beta
- old
+ new
@@ -1,18 +1,5 @@
-# Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
require 'uri'
require 'set'
require 'time'
require 'riak/client/http_backend'
require 'riak/robject'
@@ -44,17 +31,22 @@
hash["If-Match"] = robject.etag
elsif robject.prevent_stale_writes
hash["If-None-Match"] = "*"
end
unless robject.links.blank?
- hash["Link"] = robject.links.reject {|l| l.rel == "up" }.map(&:to_s).join(", ")
+ hash["Link"] = robject.links.reject {|l| l.rel == "up" }.map {|l| l.to_s(new_scheme?) }.join(", ")
end
unless robject.meta.blank?
robject.meta.each do |k,v|
hash["X-Riak-Meta-#{k}"] = v.to_s
end
end
+ unless robject.indexes.blank?
+ robject.indexes.each do |k,v|
+ hash["X-Riak-Index-#{k}"] = v.to_a.sort.map {|i| i.to_s }.join(", ")
+ end
+ end
end
end
# Load object data from an HTTP response
# @param [Hash] response a response from {Riak::Client::HTTPBackend}
@@ -64,18 +56,26 @@
extract_header(robject, response, "x-riak-vclock", :vclock)
extract_header(robject, response, "link", :links) {|v| Set.new(Link.parse(v)) }
extract_header(robject, response, "etag", :etag)
extract_header(robject, response, "last-modified", :last_modified) {|v| Time.httpdate(v) }
robject.meta = response[:headers].inject({}) do |h,(k,v)|
- if k =~ /x-riak-meta-(.*)/
+ if k =~ /x-riak-meta-(.*)/i
h[$1] = v
end
h
end
+ robject.indexes = response[:headers].inject(Hash.new {|h,k| h[k] = Set.new }) do |h,(k,v)|
+ if k =~ /x-riak-index-((?:.*)_(?:int|bin))$/i
+ key = $1
+ h[key].merge Array(v).map {|vals| vals.split(/,\s*/).map {|i| key =~ /int$/ ? i.to_i : i } }.flatten
+ end
+ h
+ end
robject.conflict = (response[:code] && response[:code].to_i == 300 && robject.content_type =~ /multipart\/mixed/)
robject.siblings = robject.conflict? ? extract_siblings(robject, response[:body]) : nil
robject.raw_data = response[:body] if response[:body].present? && !robject.conflict?
- robject
+
+ robject.conflict? ? robject.attempt_conflict_resolution : robject
end
private
def extract_header(robject, response, name, attribute=nil, &block)
extract_if_present(robject, response[:headers], name, attribute) do |value|