Class: Geminabox::Proxy::Copier
Instance Attribute Summary
Attributes inherited from FileHandler
#file_name
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from FileHandler
#file_exists?, #initialize, #local_content, #local_file_exists?, #local_path, #proxy_file_exists?, #proxy_folder_name, #proxy_folder_path, #proxy_path, #remote_content, #remote_url, #root_path
Class Method Details
.copy(file_name) ⇒ Object
8
9
10
11
12
|
# File 'lib/geminabox/proxy/copier.rb', line 8
def self.copy(file_name)
copier = new(file_name)
copier.get_file
copier
end
|
Instance Method Details
#copy_local ⇒ Object
20
21
22
|
# File 'lib/geminabox/proxy/copier.rb', line 20
def copy_local
FileUtils.cp local_path, proxy_path
end
|
#get_file ⇒ Object
14
15
16
17
18
|
# File 'lib/geminabox/proxy/copier.rb', line 14
def get_file
return true if proxy_file_exists?
return copy_local if local_file_exists?
get_remote
end
|
#get_remote ⇒ Object
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/geminabox/proxy/copier.rb', line 24
def get_remote
begin
if rc = remote_content
File.open(proxy_path, 'wb'){|f| f.write(rc) }
end
rescue
File.unlink(proxy_path) if File.exist?(proxy_path)
raise $!
end
end
|