Sha256: 1a07b28a1e4e676f0e5930edad0cce1f2b061f58a23efe596f2a156128a80324
Contents?: true
Size: 1.12 KB
Versions: 1
Compression:
Stored size: 1.12 KB
Contents
module Stack class Watcher attr_accessor :source, :target attr_accessor :generator attr_accessor :directory_watcher attr_accessor :keep_alive def initialize(generator) self.generator = generator self.source = self.generator.source self.target = self.generator.target self.keep_alive = true end def observe dirs = "" Dir.chdir(self.source) do dirs = Dir['*'].select { |x| File.directory?(x) } dirs -= ['_stack'] dirs = dirs.map { |x| "#{x}/**/*" } dirs += ['*'] end self.directory_watcher = DirectoryWatcher.new(self.source) self.directory_watcher.interval = 1 self.directory_watcher.glob = dirs self.directory_watcher.add_observer do |*args| self.generator.process! self.generator.transform! time = Time.now.strftime("%Y-%m-%d %H:%M:%S") puts "[#{time}] #{args.size} files changed and processed." end self.directory_watcher.start if self.keep_alive loop { sleep 1000 } end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
stack-0.0.6 | lib/stack/watcher.rb |