Class: Watchr::EventHandler::Portable

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/watchr/event_handlers/portable.rb

Instance Method Summary collapse

Methods included from Base

#notify

Constructor Details

#initializePortable

Returns a new instance of Portable.



6
7
8
# File 'lib/watchr/event_handlers/portable.rb', line 6

def initialize
  @reference_mtime = @reference_atime = @reference_ctime = Time.now
end

Instance Method Details

#listen(monitored_paths) ⇒ Object

Enters listening loop.

Will block control flow until application is explicitly stopped/killed.



14
15
16
17
# File 'lib/watchr/event_handlers/portable.rb', line 14

def listen(monitored_paths)
  @monitored_paths = monitored_paths
  loop { trigger; sleep(1) }
end

#refresh(monitored_paths) ⇒ Object

Update list of monitored paths.



26
27
28
# File 'lib/watchr/event_handlers/portable.rb', line 26

def refresh(monitored_paths)
  @monitored_paths = monitored_paths
end

#triggerObject

See if an event occured, and if so notify observers.



20
21
22
23
# File 'lib/watchr/event_handlers/portable.rb', line 20

def trigger #:nodoc:
  path, type = detect_event
  notify(path, type) unless path.nil?
end