Class: Automaker
- Inherits:
-
Object
- Object
- Automaker
- Defined in:
- lib/automaker.rb
Instance Method Summary collapse
- #check_arguments ⇒ Object
- #make ⇒ Object
- #print_usage ⇒ Object
- #run ⇒ Object
- #run_stream ⇒ Object
- #should_make(modified_files) ⇒ Object
Instance Method Details
#check_arguments ⇒ Object
17 18 19 |
# File 'lib/automaker.rb', line 17 def check_arguments ARGV.size > 1 end |
#make ⇒ Object
43 44 45 |
# File 'lib/automaker.rb', line 43 def make system("cd #{@path_to_watch} && make") end |
#print_usage ⇒ Object
21 22 23 24 25 |
# File 'lib/automaker.rb', line 21 def print_usage $stderr.puts "Usage: automaker </path/to/watch> <filter> [filter [filter [ etc.. ]]] You must specify the path to watch. Make is only triggered if a file whose name one of the filters is changed. (Otherwise you will likely enter an infinite loop.)" end |
#run ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/automaker.rb', line 5 def run if !check_arguments print_usage 1 else @path_to_watch = ARGV.shift @filters = ARGV run_stream 0 end end |
#run_stream ⇒ Object
27 28 29 30 31 32 |
# File 'lib/automaker.rb', line 27 def run_stream stream = FSEvents::Stream.watch(@path_to_watch) { |events| make if should_make(events.modified_files) } stream.run end |
#should_make(modified_files) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/automaker.rb', line 34 def should_make(modified_files) modified_files.each { |filename| @filters.each { |filter| return true if filename.include?(filter) } } false end |