Class: Thor::Actions::DownloadFile

Inherits:
CreateFile show all
Defined in:
lib/thor-ssh/actions/download_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base, source, destination, config = {}) ⇒ DownloadFile

Returns a new instance of DownloadFile.



11
12
13
14
# File 'lib/thor-ssh/actions/download_file.rb', line 11

def initialize(base, source, destination, config={})
  @source = source
  super(base, destination, config)
end

Instance Attribute Details

#sourceObject

Returns the value of attribute source.



9
10
11
# File 'lib/thor-ssh/actions/download_file.rb', line 9

def source
  @source
end

Instance Method Details

#downloadObject



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/thor-ssh/actions/download_file.rb', line 28

def download
  # Check for wget
  if @base.exec("which wget").strip != ''
    # We have wget, download with that
    @base.exec("wget \"#{source}\" -O \"#{destination}\"")
  elsif @base.exec("which curl").strip != ''
    # We have curl, download
    @base.exec("curl -o \"#{destination}\" \"#{source}\"")
  else
    # No program to download remotely
    raise "To download files you need either wget or curl on the remote server"
  end
end

#identical?Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
# File 'lib/thor-ssh/actions/download_file.rb', line 16

def identical?
  # TODO: find a good way to check if these are identical, then move the file
  # into place depending on user action
  # exists? && @base.destination_files.binread(destination) == render
  false
end

#invoke!Object

TODO: invoke_with_conflict_check workes except for diff



43
44
45
46
47
48
49
50
# File 'lib/thor-ssh/actions/download_file.rb', line 43

def invoke!
  # invoke_with_conflict_check do
    @base.say_status :download, source
    @base.destination_files.mkdir_p(File.dirname(destination))
    download()
  # end
  given_destination
end

#renderObject



23
24
25
# File 'lib/thor-ssh/actions/download_file.rb', line 23

def render
  @render ||= open(source) {|input| input.binmode.read }
end