class Middleman::CoreExtensions::FileWatcher

API for watching file change events

Constants

IGNORES

The default list of ignores.

Attributes

sources[R]

Public Class Methods

new(app, config={}, &block) click to toggle source

Setup the extension.

Calls superclass method
# File lib/middleman-core/core_extensions/file_watcher.rb, line 27
def initialize(app, config={}, &block)
  super

  # Setup source collection.
  @sources = ::Middleman::Sources.new(app,
                                      disable_watcher: app.config[:watcher_disable],
                                      force_polling: app.config[:watcher_force_polling],
                                      latency: app.config[:watcher_latency])

  # Add default ignores.
  IGNORES.each do |key, value|
    @sources.ignore key, :all, value
  end

  # Watch current source.
  start_watching(app.config[:source])
end

Public Instance Methods

after_configuration() click to toggle source
# File lib/middleman-core/core_extensions/file_watcher.rb, line 57
def after_configuration
  if @original_source_dir != app.config[:source]
    @watcher.update_path(app.config[:source])
  end

  @sources.start!
  @sources.poll_once!
end
before_configuration() click to toggle source
# File lib/middleman-core/core_extensions/file_watcher.rb, line 49
def before_configuration
  @sources.poll_once!
end

Protected Instance Methods

start_watching(dir) click to toggle source
# File lib/middleman-core/core_extensions/file_watcher.rb, line 72
def start_watching(dir)
  @original_source_dir = dir
  @watcher = @sources.watch :source, path: File.join(app.root, dir)
end