Permalink
Browse files

Broken, but not for long.

  • Loading branch information...
1 parent 1917950 commit e200183996b64448dc67f022369592e394c46792 @jbarnette committed Jan 28, 2009
Showing with 36 additions and 8 deletions.
  1. +2 −1 bin/lather
  2. +5 −4 lib/lather/cli.rb
  3. +29 −3 lib/lather/watcher.rb
View
@@ -2,5 +2,6 @@
require File.expand_path(File.dirname(__FILE__) + "/../lib/lather")
require "lather/cli"
-
+
+trap("INT") { puts; exit 1 }
Lather::Cli.new(STDOUT).go! ARGV
View
@@ -5,6 +5,7 @@ class Cli
def initialize out
@out = out
@globs = []
+ @command = nil
@verbose = false
@options = OptionParser.new do |o|
@@ -42,15 +43,15 @@ def go! args
@globs.concat args
exit help! if @globs.empty?
- watcher = Lather::Watcher.new @globs do |file|
+ watcher = Lather::Watcher.new @globs do |files|
if @command
- out.puts "FIXME: #{@command}"
+ @out.puts "FIXME: #{@command}"
else
- out.puts "Changed: #{file}"
+ @out.puts "Changed: #{files.join(" ")}"
end
end
- verbose "Watching: #{watcher.files.join(" ")}"
+ verbose "Watching: #{watcher.files.keys.sort.join(" ")}"
watcher.go!
end
View
@@ -4,13 +4,39 @@ class Watcher
def initialize *globs, &callback
raise ArgumentError, "need a callback" unless block_given?
-
@callback = callback
- @files = globs.flatten.collect { |g| Dir[g] }.flatten
+
+ @options = { :sleep => 1 }
+ @options.merge!(globs.pop) if globs.last.is_a? Hash
+
+ @globs = globs
+ @files = find_files
end
def go!
- puts "FIXME: go!"
+ loop do
+ unless (changed = get_changed_files).empty?
+ @callback[changed]
+ end
+
+ Kernel.sleep @options[:sleep]
+ end
+ end
+
+ private
+
+ def get_changed_files
+ ["FIXME"]
+ end
+
+ def find_files
+ files = {}
+
+ @globs.flatten.collect { |g| Dir[g] }.flatten.each do |file|
+ files[file] = File.stat(file).mtime rescue next
+ end
+
+ files
end
end
end

0 comments on commit e200183

Please sign in to comment.