Class: RMTools::ScpHelper
Instance Attribute Summary
Attributes inherited from FileWatcher
#thread
Instance Method Summary
collapse
Methods inherited from FileWatcher
#files_stats, #kill, #print_idle_time, #print_temp, #print_time, #puts_temp, #temp_string, #watch_cycle
Constructor Details
#initialize(params = {}) ⇒ ScpHelper
Returns a new instance of ScpHelper.
104
105
106
107
108
|
# File 'lib/rmtools/dev/watching.rb', line 104
def initialize(params={})
@pwd = params[:pwd] || (params[:host] ? File.join(Dir.pwd, params[:host]) : Dir.pwd)
@host = params[:host] || File.basename(@pwd)
super params
end
|
Instance Method Details
#files_mtimes ⇒ Object
110
111
112
|
# File 'lib/rmtools/dev/watching.rb', line 110
def files_mtimes
files_stats :mtime
end
|
137
138
139
140
141
142
143
144
145
146
|
# File 'lib/rmtools/dev/watching.rb', line 137
def process
if @files.b
$log.debug {[prev_time.to_f, File.mtime(@pwd+@files[0]).to_f]}
puts Painter.w("\nMODIFIED IN #@host: ") + @files*', '
@files.each {|fpath| scp fpath}
else
$log.debug {[@prev_time.to_f, File.mtime('var/rails/nzm/app/assets/stylesheets/app.css').to_f]}
@cur_time = @prev_time
end
end
|
#scp(fpath) ⇒ Object
@ fpath : “/<relative path>”
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/rmtools/dev/watching.rb', line 115
def scp(fpath)
fullpath = File.join @pwd, fpath
cmd = "scp #{fullpath.inspect} #{[@host, fpath].join(':').inspect} 2>&1"
print "`#{cmd}`: " if @debug
if res = RMTools::tick_while {`#{cmd}`}.b
puts "[ #{Painter.r_b('Error')} ]: #{res}"
else
print "[ #{Painter.g('OK')} ]"
end
end
|
#select_files ⇒ Object
131
132
133
134
135
|
# File 'lib/rmtools/dev/watching.rb', line 131
def select_files
@cur_time, @prev_time = Time.now, @cur_time
files_mtimes.select {|f, s| s.mtime >= @prev_time}.to_a.firsts
.map {|fpath| fpath.sub(@pwd, '')}
end
|
148
149
150
151
152
153
|
# File 'lib/rmtools/dev/watching.rb', line 148
def wait
(@interval*10).times {
sleep 0.1
print_idle_time
}
end
|
126
127
128
129
|
# File 'lib/rmtools/dev/watching.rb', line 126
def watch
@cur_time, @prev_time = Time.now, nil
super
end
|