Class: Coyote::FSListeners::Darwin

Inherits:
Base
  • Object
show all
Defined in:
lib/coyote/fs_listeners/darwin.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#last_event, #sha1_checksums_hash

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#modified_files, #update_last_event

Constructor Details

#initializeDarwin

Returns a new instance of Darwin.



5
6
7
8
# File 'lib/coyote/fs_listeners/darwin.rb', line 5

def initialize
  super
  @fsevent = FSEvent.new
end

Instance Attribute Details

#fseventObject (readonly)

Returns the value of attribute fsevent.



3
4
5
# File 'lib/coyote/fs_listeners/darwin.rb', line 3

def fsevent
  @fsevent
end

Class Method Details

.usable?Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/coyote/fs_listeners/darwin.rb', line 26

def self.usable?
  require 'rb-fsevent'
  if !defined?(FSEvent::VERSION) || Gem::Version.new(FSEvent::VERSION) < Gem::Version.new('0.3.9')
    notify "Please update rb-fsevent (>= 0.3.9)", :failure
    false
  else
    true
  end
rescue LoadError
  notify "Please install rb-fsevent gem for Mac OSX FSEvents support", :failure
  false
end

Instance Method Details

#on_change(&callback) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/coyote/fs_listeners/darwin.rb', line 10

def on_change(&callback)
  @fsevent.watch [Dir.pwd] do |modified_dirs|
    files = modified_files(modified_dirs)
    update_last_event
    callback.call(files)
  end
end

#startObject



18
19
20
# File 'lib/coyote/fs_listeners/darwin.rb', line 18

def start
  @fsevent.run
end

#stopObject



22
23
24
# File 'lib/coyote/fs_listeners/darwin.rb', line 22

def stop
  @fsevent.stop
end