Skip to content

Instantly share code, notes, and snippets.

@johnthethird
Created March 9, 2010 15:31
Show Gist options
  • Save johnthethird/326700 to your computer and use it in GitHub Desktop.
Save johnthethird/326700 to your computer and use it in GitHub Desktop.
module Riak
class RObject
def reload_headers
return {} if @data == "_LAZY_LOADED_"
{}.tap do |h|
h['If-None-Match'] = @etag if @etag.present?
h['If-Modified-Since'] = @last_modified.httpdate if @last_modified.present?
end
end
def data
reload(:force => true) if @data == "_LAZY_LOADED_"
@data
end
def initialize(bucket, key=nil, options={})
@bucket, @key = bucket, key
@key.gsub!(/\//,"%2f") if key
@links, @meta = Set.new, {}
if @key && options.delete(:lazy_load)
response = @bucket.client.http.head([200,404], @bucket.client.prefix, @bucket.name, @key, options, {})
if response[:code] == 200
load(response)
end
end
yield self if block_given?
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment