Class: Scaffoldhub::TemplateFile
Instance Method Summary
collapse
Methods inherited from RemoteFile
#exists?, #http_request, #remote_file_contents!
Constructor Details
#initialize(src, dest, rename, local, base_url, status_proc) ⇒ TemplateFile
Returns a new instance of TemplateFile.
4
5
6
7
8
9
10
11
|
# File 'lib/scaffoldhub/template_file.rb', line 4
def initialize(src, dest, rename, local, base_url, status_proc)
@src = src
@dest = dest || ''
@rename = rename
@local = local
@base_url = base_url
super(url, status_proc)
end
|
Instance Method Details
#dest ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/scaffoldhub/template_file.rb', line 21
def dest
if @rename
File.join(@dest, @rename)
else
File.join(@dest, File.basename(@src))
end
end
|
#download! ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/scaffoldhub/template_file.rb', line 29
def download!
if @local
raise Errno::ENOENT.new(src) unless File.exists?(src)
else
@local_path = Tempfile.new(File.basename(@src)).path
open(@local_path, "wb") do |file|
file.write(remote_file_contents!)
end
end
self
end
|
#src ⇒ Object
13
14
15
16
17
18
19
|
# File 'lib/scaffoldhub/template_file.rb', line 13
def src
if @local
File.join(@base_url, @src)
else
@local_path
end
end
|
#url ⇒ Object
41
42
43
|
# File 'lib/scaffoldhub/template_file.rb', line 41
def url
"#{@base_url}/#{@src}"
end
|