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, Contracts::VectorOf

Instance Attribute Summary collapse

Attributes inherited from Extension

#app, #options

Instance Method Summary collapse

Methods inherited from Extension

activated_extension, #add_exposed_to_context, #after_build, after_extension_activated, #after_extension_activated, #before_build, clear_after_extension_callbacks, config, expose_to_application, expose_to_config, expose_to_template, helpers, #manipulate_resource_list, option, #ready, resources

Methods included from Contracts

#Contract

Constructor Details

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

Setup the extension.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'middleman-core/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[: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

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



57
58
59
60
61
62
63
64
# File 'middleman-core/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.find_new_files!
end

#Any

This method returns an undefined value.

After we config, find new files since config can change paths.



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

Contract Any

#before_configurationObject



49
50
51
# File 'middleman-core/lib/middleman-core/core_extensions/file_watcher.rb', line 49

def before_configuration
  @sources.find_new_files!
end