Class: Knj::Event_filemod
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
Instance Method Summary collapse
- #add_path(fpath) ⇒ Object
- #destroy ⇒ Object
-
#initialize(args, &block) ⇒ Event_filemod
constructor
A new instance of Event_filemod.
Constructor Details
#initialize(args, &block) ⇒ Event_filemod
Returns a new instance of Event_filemod.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/knj/event_filemod.rb', line 4 def initialize(args, &block) @args = args @run = true @mutex = Mutex.new @args[:wait] = 1 if !@args.key?(:wait) @mtimes = {} args[:paths].each do |path| @mtimes[path] = File.mtime(path) end Knj::Thread.new do while @run do break if !@args or !@args[:paths] or @args[:paths].empty? @mutex.synchronize do @args[:paths].each do |path| changed = false if @mtimes and !@mtimes.key?(path) and @mtimes.is_a?(Hash) @mtimes[path] = File.mtime(path) end begin newdate = File.mtime(path) rescue Errno::ENOENT #file does not exist. changed = true end if !changed and newdate and @mtimes and newdate > @mtimes[path] changed = true end if changed block.call(self, path) @args[:paths].delete(path) if @args and @args[:break_when_changed] end end sleep @args[:wait] if @args and @run end end end end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
2 3 4 |
# File 'lib/knj/event_filemod.rb', line 2 def args @args end |