Class: Moneta::Adapters::Fog
Overview
Fog backend (Cloud storage services)
Instance Method Summary collapse
- #clear(options = {}) ⇒ Object
- #delete(key, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Fog
constructor
Constructor.
- #key?(key, options = {}) ⇒ Boolean
- #load(key, options = {}) ⇒ Object
- #store(key, value, options = {}) ⇒ Object
Methods inherited from Base
#[], #[]=, #close, #fetch, #increment
Methods included from Mixins::WithOptions
#expires, #prefix, #raw, #with
Constructor Details
#initialize(options = {}) ⇒ Fog
Constructor
Options:
-
:dir - Fog directory
-
Other options passed to Fog::Storage#new
15 16 17 18 19 |
# File 'lib/moneta/adapters/fog.rb', line 15 def initialize( = {}) raise ArgumentError, 'Option :dir is required' unless dir = .delete(:dir) storage = ::Fog::Storage.new() @directory = storage.directories.create(:key => dir) end |
Instance Method Details
#clear(options = {}) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/moneta/adapters/fog.rb', line 43 def clear( = {}) @directory.files.all.each do |file| file.destroy end self end |
#delete(key, options = {}) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/moneta/adapters/fog.rb', line 30 def delete(key, = {}) if value = @directory.files.get(key) body = value.body value.destroy body end end |
#key?(key, options = {}) ⇒ Boolean
21 22 23 |
# File 'lib/moneta/adapters/fog.rb', line 21 def key?(key, = {}) @directory.files.head(key) != nil end |
#load(key, options = {}) ⇒ Object
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
38 39 40 41 |
# File 'lib/moneta/adapters/fog.rb', line 38 def store(key, value, = {}) @directory.files.create(:key => key, :body => value) value end |