Class: Moneta::Adapters::Fog

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

Direct Known Subclasses

Rackspace, S3

Instance Method Summary collapse

Methods included from Defaults

#[]=, #fetch

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(options = {})
  bucket = options.delete(:namespace)
  s3 = options.delete(:cloud).new(options)
  @directory = s3.directories.create(:key => bucket)
end

Instance Method Details

#[](key) ⇒ Object



23
24
25
26
27
# File 'lib/moneta/adapters/fog.rb', line 23

def [](key)
  if value = get(key)
    deserialize(value.body)
  end
end

#clearObject

def update_key(key, options = {})

debug "update_key(key=#{key}, options=#{options.inspect})"
k = s3_key(key, false)
k.save_meta(meta_headers_from_options(options)) unless k.nil?

end



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) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/moneta/adapters/fog.rb', line 29

def delete(key)
  value = get(key)
  if value
    value.destroy
    deserialize(value.body)
  end
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/moneta/adapters/fog.rb', line 19

def key?(key)
  !@directory.files.head(key_for(key)).nil?
end

#store(key, value, options = {}) ⇒ Object



37
38
39
40
41
# File 'lib/moneta/adapters/fog.rb', line 37

def store(key, value, options = {})
  #perms = options[:perms]
  #headers = options[:headers] || {}
  @directory.files.create(:key => key_for(key), :body => serialize(value))
end