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 Attribute Summary collapse
- #backend ⇒ Object readonly
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, #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 20 |
# File 'lib/moneta/adapters/fog.rb', line 16 def initialize( = {}) raise ArgumentError, 'Option :dir is required' unless dir = .delete(:dir) @backend = [:backend] || ::Fog::Storage.new() @directory = @backend.directories.get(dir) || @backend.directories.create(key: dir) end |
Instance Attribute Details
#backend ⇒ Object (readonly)
10 11 12 |
# File 'lib/moneta/adapters/fog.rb', line 10 def backend @backend end |
Instance Method Details
#clear(options = {}) ⇒ void
This method returns an undefined value.
Clear all keys in this store
50 51 52 53 54 55 |
# File 'lib/moneta/adapters/fog.rb', line 50 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
34 35 36 37 38 39 40 |
# File 'lib/moneta/adapters/fog.rb', line 34 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
23 24 25 |
# File 'lib/moneta/adapters/fog.rb', line 23 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
28 29 30 31 |
# File 'lib/moneta/adapters/fog.rb', line 28 def load(key, = {}) value = @directory.files.get(key) value && value.body end |
#store(key, value, options = {}) ⇒ Object
Store value with key
43 44 45 46 47 |
# File 'lib/moneta/adapters/fog.rb', line 43 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 |