Permalink
Browse files

moved

  • Loading branch information...
1 parent 6e03ddd commit e53344f9a57217737efb82133a7342456e6b1d0c @seki committed Aug 29, 2011
Showing with 53 additions and 0 deletions.
  1. +53 −0 sample/demo4book/crawl.rb
View
@@ -0,0 +1,53 @@
+require 'pp'
+require 'my_drip'
+require 'monitor'
+
+class Crowler
+ include MonitorMixin
+
+ def initialize
+ super()
+ @root = File.expand_path('~/develop/git-repo/')
+ @drip = MyDrip
+ k, = @drip.head(1, 'rbcrowl-begin')[0]
+ @fence = k || 0
+ end
+
+ def last_mtime(fname)
+ k, v, = @drip.head(1, 'rbcrowl-fname=' + fname)[0]
+ (v && k > @fence) ? v[1] : Time.at(1)
+ end
+
+ def do_crowl
+ synchronize do
+ ary = []
+ Dir.chdir(@root)
+ Dir.glob('**/*.rb').each do |fname|
+ mtime = File.mtime(fname)
+ next if last_mtime(fname) >= mtime
+ @drip.write([fname, mtime, File.read(fname)],
+ 'rbcrowl', 'rbcrowl-fname=' + fname)
+ ary << fname
+ end
+ @drip.write(ary, 'rbcrowl-footprint')
+ ary
+ end
+ end
+
+ def quit
+ synchronize do
+ exit(0)
+ end
+ end
+end
+
+crowler = Crowler.new
+Thread.new do
+ while true
+ pp crowler.do_crowl
+ sleep 60
+ end
+end
+
+gets
+crowler.quit

0 comments on commit e53344f

Please sign in to comment.