Class: Guard::CoffeeScript
- Inherits:
-
Plugin
- Object
- Plugin
- Guard::CoffeeScript
- 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
- #patterns ⇒ Object readonly
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ CoffeeScript
constructor
A new instance of CoffeeScript.
-
#run_all ⇒ Object
Gets called when all files should be regenerated.
-
#run_on_modifications(paths) ⇒ Object
Gets called when watched paths and files have changes.
-
#run_on_removals(paths) ⇒ Object
Called on file(s) deletions that the Guard watches.
-
#start ⇒ Object
Gets called once when Guard starts.
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( = {}) defaults = DEFAULT_OPTIONS.clone @patterns = .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 [:input] [:output] = [:input] unless [:output] super(defaults.merge()) end |
Instance Attribute Details
#patterns ⇒ Object (readonly)
37 38 39 |
# File 'lib/guard/coffeescript.rb', line 37 def patterns @patterns end |
Instance Method Details
#run_all ⇒ Object
Gets called when all files should be regenerated.
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.
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, ) throw :task_has_failed unless success end |
#run_on_removals(paths) ⇒ Object
Called on file(s) deletions that the Guard watches.
94 95 96 |
# File 'lib/guard/coffeescript.rb', line 94 def run_on_removals(paths) Runner.remove(Inspector.clean(paths, missing_ok: true), @patterns, ) end |
#start ⇒ Object
Gets called once when Guard starts.
59 60 61 |
# File 'lib/guard/coffeescript.rb', line 59 def start run_all if [:all_on_start] end |