Class: EMDirWatcher::Platform::Mac::Watcher

Inherits:
Object
  • Object
show all
Defined in:
lib/em-dir-watcher/platform/mac.rb

Constant Summary collapse

STARTUP_DELAY =
0.5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, inclusions, exclusions) ⇒ Watcher

Returns a new instance of Watcher.


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/em-dir-watcher/platform/mac.rb', line 14

def initialize path, inclusions, exclusions
    subprocess = lambda do |ready, output|
        require "em-dir-watcher/platform/mac/rubycocoa_watcher"
        # require "em-dir-watcher/platform/mac/ffi_fsevents_watcher"
        stream = FSEventStream.new [path] do |changed_paths|
            changed_paths.each { |path| output.call path }
        end
        ready.call()
        stream.run_loop
    end
    
    @invoker = EMDirWatcher::Invokers::SubprocessInvoker.new subprocess do |path|
        code, path = path[0], path[1..-1]
        if code == ?> || code == ?-
            refresh_subtree = (code == ?>)
            yield path, refresh_subtree
        end
    end
    # Mac OS X seems to require this delay till it really starts listening for file system changes.
    # See README for explaination of the effect.
    @invoker.additional_delay = STARTUP_DELAY
end

Instance Attribute Details

#activeObject

Returns the value of attribute active


12
13
14
# File 'lib/em-dir-watcher/platform/mac.rb', line 12

def active
  @active
end

#handlerObject

Returns the value of attribute handler


12
13
14
# File 'lib/em-dir-watcher/platform/mac.rb', line 12

def handler
  @handler
end

Instance Method Details

#ready_to_use?Boolean

Returns:

  • (Boolean)

41
# File 'lib/em-dir-watcher/platform/mac.rb', line 41

def ready_to_use?; true; end

#stopObject


43
44
45
# File 'lib/em-dir-watcher/platform/mac.rb', line 43

def stop
    @invoker.stop
end

#when_ready_to_use(&ready_to_use_handler) ⇒ Object


37
38
39
# File 'lib/em-dir-watcher/platform/mac.rb', line 37

def when_ready_to_use &ready_to_use_handler
    @invoker.when_ready_to_use &ready_to_use_handler
end