Class: Middleman::CoreExtensions::FileWatcher

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

Overview

API for watching file change events

Constant Summary collapse

IGNORES =

The default list of ignores.

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

Constants included from Contracts

Contracts::PATH_MATCHER

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, define_setting, expose_to_application, expose_to_config, expose_to_template, global_config, 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
# 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)

  # 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 'lib/middleman-core/core_extensions/file_watcher.rb', line 10

def sources
  @sources
end

Instance Method Details

#after_configurationObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/middleman-core/core_extensions/file_watcher.rb', line 54

def after_configuration
  @watcher.update_config(
    disable_watcher: app.config[:watcher_disable],
    force_polling: app.config[:watcher_force_polling],
    latency: app.config[:watcher_latency],
    wait_for_delay: app.config[:watcher_wait_for_delay]
  )

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

  @sources.start!
  @sources.poll_once!
end

#Any

This method returns an undefined value.

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



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

Contract Any

#before_configurationObject



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

def before_configuration
  @sources.poll_once!
end