Class: Middleman::CoreExtensions::FileWatcher

Inherits:
Extension
  • Object
show all
Defined in:
middleman-core/lib/middleman-core/core_extensions/file_watcher.rb

Overview

API for watching file change events

Constant Summary

IGNORES =

The default list of ignores.

{
  emacs_files: /(^|\/)\.?#/,
  tilde_files: /~$/,
  ds_store: /\.DS_Store$/,
  git: /(^|\/)\.git(ignore|modules|\/)/
}

Constants included from Contracts

Contracts::PATH_MATCHER, Contracts::ResourceList

Instance Attribute Summary collapse

Attributes inherited from Extension

#app, #options

Instance Method Summary collapse

Methods inherited from Extension

activated_extension, #after_build, #after_extension_activated, after_extension_activated, #before_build, clear_after_extension_callbacks, config, helpers, option

Methods included from Contracts

#Contract

Constructor Details

#initialize(app, config = {}, &block) ⇒ FileWatcher

Setup the extension.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'middleman-core/lib/middleman-core/core_extensions/file_watcher.rb', line 21

def initialize(app, config={}, &block)
  super

  # Setup source collection.
  @sources = ::Middleman::Sources.new(app,
                                      disable_watcher: app.config[:watcher_disable],
                                      force_polling: app.config[: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])

  # Expose API to app and config.
  app.add_to_instance(:files, &method(:sources))
  app.add_to_config_context(:files, &method(:sources))
end

Instance Attribute Details

#sourcesObject (readonly)

Returns the value of attribute sources



10
11
12
# File 'middleman-core/lib/middleman-core/core_extensions/file_watcher.rb', line 10

def sources
  @sources
end

Instance Method Details

#after_configurationObject



55
56
57
58
59
60
61
62
# File 'middleman-core/lib/middleman-core/core_extensions/file_watcher.rb', line 55

def after_configuration
  if @original_source_dir != app.config[:source]
    @watcher.update_path(app.config[:source])
  end

  @sources.start!
  @sources.find_new_files!
end

#before_configurationObject



47
48
49
# File 'middleman-core/lib/middleman-core/core_extensions/file_watcher.rb', line 47

def before_configuration
  @sources.find_new_files!
end