Class: FSEvent
- Inherits:
-
Object
- Object
- FSEvent
- Defined in:
- lib/rb-fsevent/fsevent.rb,
lib/rb-fsevent/version.rb
Constant Summary collapse
- VERSION =
'0.9.8'
Instance Attribute Summary collapse
-
#callback ⇒ Object
readonly
Returns the value of attribute callback.
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
Instance Method Summary collapse
-
#initialize(args = nil, &block) ⇒ FSEvent
constructor
A new instance of FSEvent.
- #open_pipe ⇒ Object
- #process_running?(pid) ⇒ Boolean
- #run ⇒ Object
- #stop ⇒ Object
- #watch(watch_paths, options = nil, &block) ⇒ Object
Constructor Details
#initialize(args = nil, &block) ⇒ FSEvent
Returns a new instance of FSEvent.
19 20 21 |
# File 'lib/rb-fsevent/fsevent.rb', line 19 def initialize args = nil, &block watch(args, &block) unless args.nil? end |
Instance Attribute Details
#callback ⇒ Object (readonly)
Returns the value of attribute callback.
17 18 19 |
# File 'lib/rb-fsevent/fsevent.rb', line 17 def callback @callback end |
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
17 18 19 |
# File 'lib/rb-fsevent/fsevent.rb', line 17 def paths @paths end |
Instance Method Details
#open_pipe ⇒ Object
73 74 75 |
# File 'lib/rb-fsevent/fsevent.rb', line 73 def open_pipe IO.popen("'#{self.class.watcher_path}' #{} #{shellescaped_paths}") end |
#process_running?(pid) ⇒ Boolean
63 64 65 66 67 68 69 70 |
# File 'lib/rb-fsevent/fsevent.rb', line 63 def process_running?(pid) begin Process.kill(0, pid) true rescue Errno::ESRCH false end end |
#run ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rb-fsevent/fsevent.rb', line 36 def run @pipe = open_pipe @running = true # please note the use of IO::select() here, as it is used specifically to # preserve correct signal handling behavior in ruby 1.8. while @running && IO::select([@pipe], nil, nil, nil) if line = @pipe.readline modified_dir_paths = line.split(':').select { |dir| dir != "\n" } callback.call(modified_dir_paths) end end rescue Interrupt, IOError, Errno::EBADF ensure stop end |
#stop ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/rb-fsevent/fsevent.rb', line 53 def stop unless @pipe.nil? Process.kill('KILL', @pipe.pid) if process_running?(@pipe.pid) @pipe.close end rescue IOError ensure @running = false end |
#watch(watch_paths, options = nil, &block) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rb-fsevent/fsevent.rb', line 23 def watch(watch_paths, =nil, &block) @paths = watch_paths.kind_of?(Array) ? watch_paths : [watch_paths] @callback = block if .kind_of?(Hash) @options = () elsif .kind_of?(Array) @options = else @options = [] end end |