Class: Guard::Flopbox
Instance Attribute Summary collapse
-
#growl_image ⇒ Object
readonly
Returns the value of attribute growl_image.
-
#pwd ⇒ Object
readonly
Returns the value of attribute pwd.
-
#remote ⇒ Object
readonly
Returns the value of attribute remote.
-
#sftp_session ⇒ Object
readonly
Returns the value of attribute sftp_session.
Instance Method Summary collapse
-
#initialize(watchers = [], options = {}) ⇒ Flopbox
constructor
A new instance of Flopbox.
- #run_on_change(paths) ⇒ Object
Constructor Details
#initialize(watchers = [], options = {}) ⇒ Flopbox
Returns a new instance of Flopbox.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/guard/flopbox.rb', line 11 def initialize(watchers = [], = {}) @sftp_session = Net::SFTP.start([:hostname], [:user], [:sftp_opts]) @remote = [:remote] @debug = [:debug] @growl = [:growl] @growl_image = [:growl_image] @pwd = Dir.pwd log "Initialized with watchers = #{watchers.inspect}" log "Initialized with options = #{.inspect}" super end |
Instance Attribute Details
#growl_image ⇒ Object (readonly)
Returns the value of attribute growl_image.
9 10 11 |
# File 'lib/guard/flopbox.rb', line 9 def growl_image @growl_image end |
#pwd ⇒ Object (readonly)
Returns the value of attribute pwd.
9 10 11 |
# File 'lib/guard/flopbox.rb', line 9 def pwd @pwd end |
#remote ⇒ Object (readonly)
Returns the value of attribute remote.
9 10 11 |
# File 'lib/guard/flopbox.rb', line 9 def remote @remote end |
#sftp_session ⇒ Object (readonly)
Returns the value of attribute sftp_session.
9 10 11 |
# File 'lib/guard/flopbox.rb', line 9 def sftp_session @sftp_session end |
Instance Method Details
#run_on_change(paths) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/guard/flopbox.rb', line 25 def run_on_change(paths) paths.each do |path| local_file = File.join(pwd, path) remote_file = File.join(remote, path) attempts = 0 begin log "Upload #{local_file} => #{remote_file}" sftp_session.upload!(local_file, remote_file) rescue Net::SFTP::StatusException => ex log "Exception on upload #{path} - directory likely doesn't exist" attempts += 1 remote_dir = File.dirname(remote_file) recursively_create_dirs( remote_dir ) retry if (attempts < 3) log "Exceeded 3 attempts to upload #{path}" end growl("Synced:\n#{paths.join("\n")}") end end |