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.
103
104
105
106
107
|
# File 'lib/rmtools/dev/watching.rb', line 103
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
109
110
111
|
# File 'lib/rmtools/dev/watching.rb', line 109
def files_mtimes
files_stats :mtime
end
|
136
137
138
139
140
141
142
143
144
145
|
# File 'lib/rmtools/dev/watching.rb', line 136
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>”
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/rmtools/dev/watching.rb', line 114
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.rb('Error')} ]: #{res}"
else
print "[ #{Painter.g('OK')} ]"
end
end
|
#select_files ⇒ Object
130
131
132
133
134
|
# File 'lib/rmtools/dev/watching.rb', line 130
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
|
147
148
149
150
151
152
|
# File 'lib/rmtools/dev/watching.rb', line 147
def wait
(@interval*10).times {
sleep 0.1
print_idle_time
}
end
|
125
126
127
128
|
# File 'lib/rmtools/dev/watching.rb', line 125
def watch
@cur_time, @prev_time = Time.now, nil
super
end
|