Class: Defog::FogWrapper::Local

Inherits:
Defog::FogWrapper show all
Defined in:
lib/defog/fog_wrapper.rb

Instance Attribute Summary

Attributes inherited from Defog::FogWrapper

#fog_connection, #fog_directory, #location

Instance Method Summary collapse

Methods inherited from Defog::FogWrapper

connect, #fog_head, #get_file, #put_file

Constructor Details

#initialize(opts = {}) ⇒ Local

Returns a new instance of Local.



42
43
44
45
46
47
48
# File 'lib/defog/fog_wrapper.rb', line 42

def initialize(opts={})
  opts = opts.keyword_args(:local_root => :required)
  @local_root = Pathname.new(opts.local_root).realpath
  @location = @local_root.to_s.gsub(%r{/},'_')
  @fog_connection = Fog::Storage.new(:provider => provider, :local_root => @local_root)
  @fog_directory = @fog_connection.directories.get('.')
end

Instance Method Details

#get_md5(key) ⇒ Object



50
51
52
# File 'lib/defog/fog_wrapper.rb', line 50

def get_md5(key)
  Digest::MD5.hexdigest(fog_head(key).body)
end

#providerObject



40
# File 'lib/defog/fog_wrapper.rb', line 40

def provider ; :local ; end

#url(key, expiry) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/defog/fog_wrapper.rb', line 54

def url(key, expiry)
  localpath = Pathname.new("#{@local_root}/#{key}").expand_path
  if defined?(Rails)
    relative = localpath.relative_path_from Rails.root + "public" rescue nil
    return "/" + relative.to_s if relative and not relative.to_s.start_with? "../"
  end
  "file://#{localpath}"
end