Class: Moneta::Adapters::Fog
- Inherits:
-
Object
- Object
- Moneta::Adapters::Fog
- Includes:
- Defaults
- Defined in:
- lib/moneta/adapters/fog.rb
Overview
Fog backend (Cloud storage services)
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 included from Defaults
#[], #[]=, #close, #decrement, #fetch, #increment
Methods included from OptionSupport
#expires, #prefix, #raw, #with
Constructor Details
#initialize(options = {}) ⇒ Fog
Returns a new instance of Fog.
13 14 15 16 17 |
# File 'lib/moneta/adapters/fog.rb', line 13 def initialize( = {}) raise ArgumentError, 'Option :dir is required' unless dir = .delete(:dir) storage = ::Fog::Storage.new() @directory = storage.directories.get(dir) || storage.directories.create(:key => dir) end |
Instance Method Details
#clear(options = {}) ⇒ void
This method returns an undefined value.
Clear all keys in this store
46 47 48 49 50 51 |
# File 'lib/moneta/adapters/fog.rb', line 46 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
31 32 33 34 35 36 37 |
# File 'lib/moneta/adapters/fog.rb', line 31 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
20 21 22 |
# File 'lib/moneta/adapters/fog.rb', line 20 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
25 26 27 28 |
# File 'lib/moneta/adapters/fog.rb', line 25 def load(key, = {}) value = @directory.files.get(key) value && value.body end |
#store(key, value, options = {}) ⇒ Object
Store value with key
40 41 42 43 |
# File 'lib/moneta/adapters/fog.rb', line 40 def store(key, value, = {}) @directory.files.create(.merge(:key => key, :body => value)) value end |