lib/scaffoldhub/template_file.rb in scaffoldhub-0.0.1 vs lib/scaffoldhub/template_file.rb in scaffoldhub-0.0.2

- old
+ new

@@ -1,31 +1,37 @@ module Scaffoldhub class TemplateFile < RemoteFile - def initialize(src, dest, status_proc) + def initialize(src, dest, local, base_url, status_proc) @src = src @dest = dest || '' - @base_url = Scaffoldhub::Helper.scaffold.base_url + @local = local + @base_url = base_url super(status_proc) end def src - if Scaffoldhub::Helper.scaffold.local + if @local File.join(@base_url, @src) else @local_path end end def dest File.join(@dest, File.basename(@src)) end - def download - @local_path = Tempfile.new(File.basename(@src)).path - open(@local_path, "wb") do |file| - file.write(super) + 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 def url "#{@base_url}/#{@src}" end