class RemoteResource::AttributeStorageValue

Public Class Methods

new(attribute) click to toggle source
# File lib/remote_resource/attribute_storage_value.rb, line 15
def initialize(attribute)
  @attribute = attribute
  @storage_entry = nil
end

Public Instance Methods

fetch() click to toggle source
# File lib/remote_resource/attribute_storage_value.rb, line 28
def fetch
  @attribute.with_error_handling action: :fetch do
    attr_client = AttributeHttpClient.new(@attribute)
    write(StorageEntry.from_response(attr_client.get))
  end
end
storage_entry() click to toggle source
# File lib/remote_resource/attribute_storage_value.rb, line 51
def storage_entry
  return @storage_entry if @storage_entry
  instrument_attribute('storage_lookup', @attribute) do
    storages.each do |storage|
      if (storage_entry = storage.read_key(@attribute.key.for_storage))
        return (@storage_entry = storage_entry)
      end
    end
    return (@storage_entry = NullStorageEntry.new)
  end
end
storages() click to toggle source
# File lib/remote_resource/attribute_storage_value.rb, line 24
def storages
  RemoteResource.storages
end
validate() click to toggle source
# File lib/remote_resource/attribute_storage_value.rb, line 35
def validate
  @attribute.with_error_handling action: :validate do
    attr_client = AttributeHttpClient.new(@attribute)
    response = attr_client.get(headers_for_validation)
    write(StorageEntry.from_response(response))
    response.headers['status'] == '304 Not Modified'
  end
end
value() click to toggle source
# File lib/remote_resource/attribute_storage_value.rb, line 20
def value
  storage_entry.data[@attribute.name]
end
write(storage_entry) click to toggle source
# File lib/remote_resource/attribute_storage_value.rb, line 44
def write(storage_entry)
  @storage_entry = nil
  storages.each do |storage|
    storage.write_key(@attribute.key.for_storage, storage_entry)
  end
end