Class: Defog::FogWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/defog/fog_wrapper.rb

Overview

:nodoc: all

Direct Known Subclasses

Aws, Local

Defined Under Namespace

Classes: Aws, Local

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fog_connectionObject (readonly)

Returns the value of attribute fog_connection.



9
10
11
# File 'lib/defog/fog_wrapper.rb', line 9

def fog_connection
  @fog_connection
end

#fog_directoryObject (readonly)

Returns the value of attribute fog_directory.



10
11
12
# File 'lib/defog/fog_wrapper.rb', line 10

def fog_directory
  @fog_directory
end

#locationObject (readonly)

Returns the value of attribute location.



8
9
10
# File 'lib/defog/fog_wrapper.rb', line 8

def location
  @location
end

Class Method Details

.connect(opts = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/defog/fog_wrapper.rb', line 12

def self.connect(opts={})
  opts = opts.keyword_args(:provider => :required, :OTHERS => :optional)
  provider = opts.delete(:provider)
  klass = begin
            self.const_get(provider.to_s.capitalize, false)
          rescue NameError
            raise ArgumentError, "#{provider.inspect} is not a supported fog storage provider"
          end
  klass.new(opts)
end

Instance Method Details

#fog_head(key) ⇒ Object



35
36
37
# File 'lib/defog/fog_wrapper.rb', line 35

def fog_head(key)
  fog_directory.files.head(key)
end

#get_file(key, path) ⇒ Object

Raises:



23
24
25
26
27
28
29
# File 'lib/defog/fog_wrapper.rb', line 23

def get_file(key, path)
  raise Error::NoCloudFile, "No such file in #{provider} #{location}: #{key}" unless fog_head(key)
  return if path.exist? and Digest::MD5.hexdigest(path.read) == get_md5(key)
  path.open("w") do |f|
    f.write(fog_head(key).body)
  end
end

#put_file(key, path) ⇒ Object



31
32
33
# File 'lib/defog/fog_wrapper.rb', line 31

def put_file(key, path)
  fog_directory.files.create(:key => key, :body => path.open)
end