class Gazr::EventHandler::Unix::SingleFileWatcher

Used by Rev. Wraps a monitored path, and ‘Rev::Loop` will call its callback on file events.

@private

Attributes

handler[RW]

Stores a reference back to handler so we can call its {Base#notify notify} method with file event info

@return [EventHandler::Base]

Public Class Methods

new(path) click to toggle source

@param [String] path

single file to monitor
Calls superclass method
# File lib/gazr/event_handlers/unix.rb, line 23
def initialize(path)
  super
  update_reference_times
end

Public Instance Methods

on_change() click to toggle source

Callback. Called on file change event. Delegates to {Controller#update}, passing in path and event type

@return [undefined]

# File lib/gazr/event_handlers/unix.rb, line 41
def on_change
  self.class.handler.notify(path, type)
  update_reference_times unless type == :deleted
end
pathname() click to toggle source

File’s path as a Pathname

@return [Pathname]

# File lib/gazr/event_handlers/unix.rb, line 32
def pathname
  @pathname ||= Pathname(@path)
end

Private Instance Methods

type() click to toggle source

Type of latest event.

A single type is determined, even though more than one stat times may have changed on the file. The type is the first to match in the following hierarchy:

:deleted, :modified (mtime), :accessed (atime), :changed (ctime)

@return [Symbol] type

latest event's type
# File lib/gazr/event_handlers/unix.rb, line 68
def type
  return :deleted   if !pathname.exist?
  return :modified  if  pathname.mtime > @reference_mtime
  return :accessed  if  pathname.atime > @reference_atime
  return :changed   if  pathname.ctime > @reference_ctime
end
update_reference_times() click to toggle source

@todo improve ENOENT error handling

# File lib/gazr/event_handlers/unix.rb, line 49
def update_reference_times
  @reference_atime = pathname.atime
  @reference_mtime = pathname.mtime
  @reference_ctime = pathname.ctime
rescue Errno::ENOENT
  retry
end