Class: Moneta::Adapters::Fog
- Inherits:
-
Moneta::Adapter
- Object
- Moneta::Adapter
- Moneta::Adapters::Fog
- Defined in:
- lib/moneta/adapters/fog.rb
Overview
Fog backend (Cloud storage services)
Instance Attribute Summary
Attributes inherited from Moneta::Adapter
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 = {}) ⇒ Fog
constructor
A new instance of Fog.
-
#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 inherited from Moneta::Adapter
backend, backend_block, backend_required?
Methods included from Config
Methods included from Defaults
#[], #[]=, #close, #create, #decrement, #each_key, #features, #fetch, #fetch_values, included, #increment, #merge!, #slice, #supports?, #update, #values_at
Methods included from OptionSupport
#expires, #prefix, #raw, #with
Constructor Details
#initialize(options = {}) ⇒ Fog
Returns a new instance of Fog.
16 17 18 19 |
# File 'lib/moneta/adapters/fog.rb', line 16 def initialize( = {}) super @directory = backend.directories.get(config.dir) || backend.directories.create(key: config.dir) end |
Instance Method Details
#clear(options = {}) ⇒ void
This method returns an undefined value.
Clear all keys in this store
49 50 51 52 53 54 |
# File 'lib/moneta/adapters/fog.rb', line 49 def clear( = {}) @directory.files.all.each do |file| file.destroy end self end |
#delete(key, options = {}) ⇒ Object
Delete the key from the store and return the current value
33 34 35 36 37 38 39 |
# File 'lib/moneta/adapters/fog.rb', line 33 def delete(key, = {}) if value = @directory.files.get(key) body = value.body value.destroy body end end |
#key?(key, options = {}) ⇒ Boolean
Exists the value with key
22 23 24 |
# File 'lib/moneta/adapters/fog.rb', line 22 def key?(key, = {}) @directory.files.head(key) != nil end |
#load(key, options = {}) ⇒ Object
Fetch value with key. Return nil if the key doesn’t exist
27 28 29 30 |
# File 'lib/moneta/adapters/fog.rb', line 27 def load(key, = {}) value = @directory.files.get(key) value && value.body end |
#store(key, value, options = {}) ⇒ Object
Store value with key
42 43 44 45 46 |
# File 'lib/moneta/adapters/fog.rb', line 42 def store(key, value, = {}) value = value.dup if value.frozen? # HACK: Fog needs unfrozen string @directory.files.create(.merge(key: key, body: value)) value end |