Created
December 23, 2008 14:59
-
-
Save cristibalan/39349 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby -w | |
## | |
# By Mike Clark | |
# | |
# From http://www.pragmaticautomation.com/cgi-bin/pragauto.cgi/Monitor/StakingOutFileChanges.rdoc | |
# | |
# Watches files and runs a command when any of them are modified. | |
# | |
# Can use Ruby's Dir[] to get file glob. Quote your args to take advantage of this. | |
# | |
# rstakeout 'rake test:recent' **/*.rb | |
# => Unquoted uses the shell...only watches Ruby files one directory down | |
# | |
# rstakeout 'rake test:recent' '**/*.rb' | |
# => Quoted uses Ruby...watches all Ruby files in all directories and subdirectories | |
command = ARGV.shift | |
files = {} | |
ARGV.each do |arg| | |
Dir[arg].each { |file| | |
files[file] = File.mtime(file) | |
} | |
end | |
puts "=> first run" | |
puts "=> #{command}" | |
system(command) | |
puts "=> done" | |
puts "Watching #{files.keys.join(', ')}\n\nFiles: #{files.keys.length}" | |
trap('INT') do | |
puts "\nQuitting..." | |
exit | |
end | |
loop do | |
sleep 1 | |
changed_file, last_changed = files.find { |file, last_changed| | |
File.mtime(file) > last_changed | |
} | |
if changed_file | |
files[changed_file] = File.mtime(changed_file) | |
puts "=> #{changed_file} changed" | |
puts "=> #{command}" | |
system(command) | |
puts "=> done" | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# usage: | |
# tt "test/controllers/user/*.rb" | |
# tt test/models/comic_test.rb models | |
# tt test/models/comic_test.rb -l 20 models | |
files = ARGV.shift | |
dir = ARGV.pop | |
if dir.nil? | |
dir = "" | |
else | |
if %w(controllers helpers models views).include? dir | |
dir += "/" | |
case dir | |
when "models" | |
moredirs = "test/unit/**/*.rb" | |
when "controllers" | |
moredirs = "test/functional/**/*.rb" | |
end | |
else | |
ARGV.push dir | |
dir = "" | |
end | |
end | |
action = "ruby #{files} #{ARGV.join(" ")}" | |
cmd = %(rstakeout.rb "#{action}" "lib/**/*.rb" "app/#{dir}**/*.rb" "test/factories/**/*.rb" "test/#{dir}**/*.rb" #{moredirs} "slices/*/app/#{dir}**/*.rb") | |
system(cmd) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment