Class: Moneta::Adapters::RestClient
- Inherits:
-
Object
- Object
- Moneta::Adapters::RestClient
- Includes:
- Defaults
- Defined in:
- lib/moneta/adapters/restclient.rb
Overview
Moneta rest client backend which works together with ‘Rack::MonetaRest`
Instance Method Summary collapse
-
#clear(options = {}) ⇒ void
Clear all keys in this store.
-
#delete(key, options = {}) ⇒ Object
Delete the key from the store and return the current value.
-
#initialize(options = {}) ⇒ RestClient
constructor
A new instance of RestClient.
-
#key?(key, options = {}) ⇒ Boolean
Exists the value with key.
-
#load(key, options = {}) ⇒ Object
Fetch value with key.
-
#store(key, value, options = {}) ⇒ Object
Store value with key.
Methods included from Defaults
#[], #[]=, #close, #decrement, #fetch, #increment
Methods included from OptionSupport
#expires, #prefix, #raw, #with
Constructor Details
#initialize(options = {}) ⇒ RestClient
Returns a new instance of RestClient.
12 13 14 |
# File 'lib/moneta/adapters/restclient.rb', line 12 def initialize( = {}) raise ArgumentError, 'Option :url is required' unless @url = [:url] end |
Instance Method Details
#clear(options = {}) ⇒ void
This method returns an undefined value.
Clear all keys in this store
41 42 43 44 |
# File 'lib/moneta/adapters/restclient.rb', line 41 def clear( = {}) HTTPI.delete(@url) self end |
#delete(key, options = {}) ⇒ Object
Delete the key from the store and return the current value
35 36 37 38 |
# File 'lib/moneta/adapters/restclient.rb', line 35 def delete(key, = {}) response = HTTPI.delete(@url + key) response.code == 200 ? response.body : nil end |
#key?(key, options = {}) ⇒ Boolean
Exists the value with key
17 18 19 20 |
# File 'lib/moneta/adapters/restclient.rb', line 17 def key?(key, = {}) response = HTTPI.head(@url + key) response.code == 200 end |
#load(key, options = {}) ⇒ Object
Fetch value with key. Return nil if the key doesn’t exist
23 24 25 26 |
# File 'lib/moneta/adapters/restclient.rb', line 23 def load(key, = {}) response = HTTPI.get(@url + key) response.code == 200 ? response.body : nil end |
#store(key, value, options = {}) ⇒ Object
Store value with key
29 30 31 32 |
# File 'lib/moneta/adapters/restclient.rb', line 29 def store(key, value, = {}) HTTPI.post(@url + key, value) value end |