Class: Watchr::EventHandler::Portable

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Base

#notify

Constructor Details

#initializePortable

Returns a new instance of Portable.



9
10
11
# File 'lib/watchr/event_handlers/portable.rb', line 9

def initialize
  @reference_mtime = Time.now
end

Instance Attribute Details

#monitored_pathsObject

Returns the value of attribute monitored_paths.



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

def monitored_paths
  @monitored_paths
end

#reference_mtimeObject

Returns the value of attribute reference_mtime.



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

def reference_mtime
  @reference_mtime
end

Instance Method Details

#listen(monitored_paths) ⇒ Object

Enters listening loop.

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



17
18
19
20
# File 'lib/watchr/event_handlers/portable.rb', line 17

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

#refresh(monitored_paths) ⇒ Object

Update list of monitored paths.



29
30
31
# File 'lib/watchr/event_handlers/portable.rb', line 29

def refresh(monitored_paths)
  @monitored_paths = monitored_paths
end

#triggerObject

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



23
24
25
26
# File 'lib/watchr/event_handlers/portable.rb', line 23

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