Class: Guard::Treetop
- Includes:
- TreetopVersion
- Defined in:
- lib/guard/treetop.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ :all_on_start => false }
Constants included from TreetopVersion
Guard::TreetopVersion::VERSION
Instance Attribute Summary collapse
-
#compiler ⇒ Object
readonly
Returns the value of attribute compiler.
Instance Method Summary collapse
-
#initialize(watchers = [], options = {}) ⇒ Treetop
constructor
A new instance of Treetop.
- #run_all ⇒ Object
- #run_on_changes(paths) ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(watchers = [], options = {}) ⇒ Treetop
Returns a new instance of Treetop.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/guard/treetop.rb', line 16 def initialize(watchers=[], ={}) watchers ||= [] defaults = DEFAULT_OPTIONS.clone if [:input] input = .delete(:input) defaults.merge!({:output => input}) watchers << ::Guard::Watcher.new(%r{#{input}/(.+)(\.treetop|\.tt)}) end super(watchers, defaults.merge!()) @compiler = ::Treetop::Compiler::GrammarCompiler.new end |
Instance Attribute Details
#compiler ⇒ Object (readonly)
Returns the value of attribute compiler.
14 15 16 |
# File 'lib/guard/treetop.rb', line 14 def compiler @compiler end |
Instance Method Details
#run_all ⇒ Object
35 36 37 |
# File 'lib/guard/treetop.rb', line 35 def run_all run_on_changes(Watcher.match_files(self, Dir.glob('**/*.{tt,treetop}'))) end |
#run_on_changes(paths) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/guard/treetop.rb', line 39 def run_on_changes(paths) tuples = paths.map do |path| basename = File.basename(path).gsub(/\.(tt|treetop)\z/, '.rb') dirname = [:output] || File.dirname(path) output = File.join(dirname, basename) [path, output] end tuples.each { |e| compiler.compile(*e) } rescue StandardError throw :task_has_failed end |
#start ⇒ Object
31 32 33 |
# File 'lib/guard/treetop.rb', line 31 def start run_all if [:all_on_start] end |