Sha256: e2ece5d274b5cdb63c6742021e671aa8fe6634f48ec10bac273e60395d3852bf

Contents?: true

Size: 897 Bytes

Versions: 8

Compression:

Stored size: 897 Bytes

Contents

module Scaffoldhub
  class TemplateFile < RemoteFile

    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

    def src
      if @local
        File.join(@base_url, @src)
      else
        @local_path
      end
    end

    def dest
      if @rename
        File.join(@dest, @rename)
      else
        File.join(@dest, File.basename(@src))
      end
    end

    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

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
scaffoldhub-0.1.1 lib/scaffoldhub/template_file.rb
scaffoldhub-0.1.0 lib/scaffoldhub/template_file.rb
scaffoldhub-0.0.14 lib/scaffoldhub/template_file.rb
scaffoldhub-0.0.13 lib/scaffoldhub/template_file.rb
scaffoldhub-0.0.12 lib/scaffoldhub/template_file.rb
scaffoldhub-0.0.11 lib/scaffoldhub/template_file.rb
scaffoldhub-0.0.10 lib/scaffoldhub/template_file.rb
scaffoldhub-0.0.8 lib/scaffoldhub/template_file.rb