Class: Guard::Autoupload
Instance Method Summary collapse
-
#initialize(watchers = [], options = {}) ⇒ Autoupload
constructor
A new instance of Autoupload.
- #log(message) ⇒ Object
- #quiet? ⇒ Boolean
- #run_on_change(paths) ⇒ Object
- #run_on_removals(paths) ⇒ Object
- #stop ⇒ Object
- #verbose? ⇒ Boolean
Constructor Details
#initialize(watchers = [], options = {}) ⇒ Autoupload
Returns a new instance of Autoupload.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/guard/autoupload.rb', line 11 def initialize(watchers = [], = {}) super @instance = self if [:protocol] == :scp @session = SCPSession.new( [:host], [:port] || 22, [:user], [:password], self ) elsif [:protocol] == :sftp @session = SFTPSession.new( [:host], [:port] || 22, [:user], [:password], @instance ) elsif [:protocol] == :ftp @session = FTPSession.new( [:host], [:port] || 21, [:user], [:password] ) else throw :task_has_failed end @remote = [:remote] @local = Dir.pwd @verbose = [:verbose] @quiet = [:quiet] unless verbose? output = .dup output[:password] = [:password].gsub(/./, '*') if .include? :password log "Initialized with watchers #{watchers.inspect}" if verbose? log "Initialized with options #{output.inspect}" unless quiet? end |
Instance Method Details
#log(message) ⇒ Object
106 107 108 |
# File 'lib/guard/autoupload.rb', line 106 def log() puts "[#{Time.now}] #{}" end |
#quiet? ⇒ Boolean
102 103 104 |
# File 'lib/guard/autoupload.rb', line 102 def quiet? @quiet || false end |
#run_on_change(paths) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/guard/autoupload.rb', line 52 def run_on_change(paths) paths.each do |path| local_file = File.join(@local, path) remote_file = File.join(@remote, path) attempts = 0 begin log "Upload #{local_file} => #{remote_file}" if verbose? @session.upload!(local_file, remote_file) log "Uploaded #{path}" unless quiet? rescue => ex log "Exception on uploading #{path}\n#{ex.inspect}" log ex.backtrace.join("\n") if verbose? attempts += 1 remote_dir = File.dirname(remote_file) recursively_create_dirs(remote_dir) retry if attempts < 3 log "Exceeded 3 attempts to upload #{path}" throw :task_has_failed end end msg = "Uploaded:\n#{paths.join("\n")}" ::Guard::Notifier.notify msg, :title => "Uploaded" end |
#run_on_removals(paths) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/guard/autoupload.rb', line 79 def run_on_removals(paths) paths.each do |path| remote_file = File.join(@remote, path) begin log "Delete #{remote_file}" if verbose? @session.remove!(remote_file) rescue => ex log "Exception on deleting #{path}\n#{ex.inspect}" log ex.backtrace.join("\n") if verbose? end log "Deleted #{path}" unless quiet? end msg = "Deleted:\n#{paths.join("\n")}" ::Guard::Notifier.notify msg, :title => "Deleted" end |
#stop ⇒ Object
110 111 112 113 114 115 |
# File 'lib/guard/autoupload.rb', line 110 def stop log "Tearing down connections" unless quiet? if @session.is_a? SCPSession @session.close end end |
#verbose? ⇒ Boolean
98 99 100 |
# File 'lib/guard/autoupload.rb', line 98 def verbose? @verbose || false end |