Class: Defog::FogWrapper
- Inherits:
-
Object
- Object
- Defog::FogWrapper
- Defined in:
- lib/defog/fog_wrapper.rb
Overview
:nodoc: all
Defined Under Namespace
Instance Attribute Summary collapse
-
#fog_connection ⇒ Object
readonly
Returns the value of attribute fog_connection.
-
#fog_directory ⇒ Object
readonly
Returns the value of attribute fog_directory.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#fog_connection ⇒ Object (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_directory ⇒ Object (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 |
#location ⇒ Object (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
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 |