Class: Defog::FogWrapper::Local
- Inherits:
-
Defog::FogWrapper
- Object
- Defog::FogWrapper
- Defog::FogWrapper::Local
- Defined in:
- lib/defog/fog_wrapper.rb
Instance Attribute Summary
Attributes inherited from Defog::FogWrapper
#fog_connection, #fog_directory, #location, #logger, #prefix
Instance Method Summary collapse
- #get_md5(key) ⇒ Object
-
#initialize(opts = {}) ⇒ Local
constructor
A new instance of Local.
- #provider ⇒ Object
- #url(key, expiry) ⇒ Object
Methods inherited from Defog::FogWrapper
connect, #each, #fog_delete, #fog_head, #get_file, #put_file
Constructor Details
#initialize(opts = {}) ⇒ Local
Returns a new instance of Local.
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/defog/fog_wrapper.rb', line 77 def initialize(opts={}) super(opts) opts = opts.keyword_args(:local_root => :required) @local_root = Pathname.new(opts.local_root) @local_root.mkpath unless @local_root.exist? @local_root = @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
88 89 90 |
# File 'lib/defog/fog_wrapper.rb', line 88 def get_md5(key) Digest::MD5.hexdigest(fog_head(key).body) end |
#provider ⇒ Object
75 |
# File 'lib/defog/fog_wrapper.rb', line 75 def provider ; :local ; end |
#url(key, expiry) ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'lib/defog/fog_wrapper.rb', line 92 def url(key, expiry) localpath = Pathname.new("#{@local_root}/#{@prefix}#{key}"). 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 |