Class: Guard::CoffeeScript

Inherits:
Plugin
  • Object
show all
Defined in:
lib/guard/coffeescript.rb,
lib/guard/coffeescript/runner.rb,
lib/guard/coffeescript/formatter.rb,
lib/guard/coffeescript/inspector.rb

Overview

The CoffeeScript guard that gets notifications about the following Guard events: ‘start`, `stop`, `reload`, `run_all` and `run_on_change`.

Defined Under Namespace

Modules: Formatter, Inspector, Runner

Constant Summary collapse

DEFAULT_OPTIONS =
{
  bare: false,
  shallow: false,
  hide_success: false,
  noop: false,
  error_to_js: false,
  all_on_start: false,
  source_map: false
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ CoffeeScript

Returns a new instance of CoffeeScript.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/guard/coffeescript.rb', line 39

def initialize(options = {})
  defaults = DEFAULT_OPTIONS.clone

  @patterns = options.dup.delete(:patterns) || []

  msg = 'Invalid :patterns argument. Expected: Array, got %s'
  fail ArgumentError, format(msg, @patterns.inspect) unless @patterns.is_a?(Array)

  msg = ':input option not provided (see current template Guardfile)'
  fail msg unless options[:input]

  options[:output] = options[:input] unless options[:output]

  super(defaults.merge(options))
end

Instance Attribute Details

#patternsObject (readonly)

Parameters:

  • options (Hash)

    the options for the Guard



37
38
39
# File 'lib/guard/coffeescript.rb', line 37

def patterns
  @patterns
end

Instance Method Details

#run_allObject

Gets called when all files should be regenerated.

Raises:

  • (:task_has_failed)

    when stop has failed



67
68
69
70
71
72
73
74
75
76
# File 'lib/guard/coffeescript.rb', line 67

def run_all
  found = Dir.glob('**{,/*/**}/*.{coffee,coffee.md,litcoffee}')
  found.select! do |file|
    @patterns.any? do |pattern|
      pattern.match(file)
    end
  end

  run_on_modifications(found)
end

#run_on_modifications(paths) ⇒ Object

Gets called when watched paths and files have changes.

Parameters:

  • paths (Array<String>)

    the changed paths and files

Raises:

  • (:task_has_failed)

    when stop has failed



83
84
85
86
87
# File 'lib/guard/coffeescript.rb', line 83

def run_on_modifications(paths)
  _changed_files, success = Runner.run(Inspector.clean(paths), @patterns, options)

  throw :task_has_failed unless success
end

#run_on_removals(paths) ⇒ Object

Called on file(s) deletions that the Guard watches.

Parameters:

  • paths (Array<String>)

    the deleted files or paths

Raises:

  • (:task_has_failed)

    when run_on_change has failed



94
95
96
# File 'lib/guard/coffeescript.rb', line 94

def run_on_removals(paths)
  Runner.remove(Inspector.clean(paths, missing_ok: true), @patterns, options)
end

#startObject

Gets called once when Guard starts.

Raises:

  • (:task_has_failed)

    when stop has failed



59
60
61
# File 'lib/guard/coffeescript.rb', line 59

def start
  run_all if options[:all_on_start]
end