/usr/lib/ruby/vendor_ruby/moneta/adapters/restclient.rb is in ruby-moneta 0.7.20-2.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | require 'faraday'
module Moneta
module Adapters
# Moneta rest client backend which works together with {Rack::MonetaRest}
# @api public
class RestClient
include Defaults
attr_reader :backend
# @param [Hash] options
# @option options [String] :url URL
# @option options [Faraday connection] :backend Use existing backend instance
def initialize(options = {})
raise ArgumentError, 'Option :url is required' unless url = options[:url]
@backend = options[:backend] || ::Faraday.new(:url => url)
end
# (see Proxy#key?)
def key?(key, options = {})
@backend.head(key).status == 200
end
# (see Proxy#load)
def load(key, options = {})
response = @backend.get(key)
response.status == 200 ? response.body : nil
end
# (see Proxy#store)
def store(key, value, options = {})
response = @backend.post(key, value)
raise "HTTP error #{response.status}" unless response.status == 200
value
end
# (see Proxy#delete)
def delete(key, options = {})
response = @backend.delete(key)
response.status == 200 ? response.body : nil
end
# (see Proxy#clear)
def clear(options = {})
@backend.delete ''
self
end
end
end
end
|