Class: Moneta::Adapters::Fog

Inherits:
Base
  • Object
show all
Defined in:
lib/moneta/adapters/fog.rb

Overview

Fog backend (Cloud storage services)

Instance Method Summary collapse

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

Parameters:

  • options (Hash) (defaults to: {})

Raises:

  • (ArgumentError)


15
16
17
18
19
# File 'lib/moneta/adapters/fog.rb', line 15

def initialize(options = {})
  raise ArgumentError, 'Option :dir is required' unless dir = options.delete(:dir)
  storage = ::Fog::Storage.new(options)
  @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(options = {})
  @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, options = {})
  if value = @directory.files.get(key)
    body = value.body
    value.destroy
    body
  end
end

#key?(key, options = {}) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/moneta/adapters/fog.rb', line 21

def key?(key, options = {})
  @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, options = {})
  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, options = {})
  @directory.files.create(:key => key, :body => value)
  value
end