Class: Guard::Motion
- Defined in:
- lib/guard/motion.rb,
lib/guard/motion/runner.rb,
lib/guard/motion/results_parser.rb
Defined Under Namespace
Classes: ResultsParser, Runner
Instance Method Summary collapse
-
#initialize(watchers = [], options = {}) ⇒ Motion
constructor
Initialize a Guard.
-
#reload ⇒ Object
Called when ‘reload|r|z + enter` is pressed.
-
#run_all ⇒ Object
Called when just ‘enter` is pressed This method should be principally used for long action like running all specs/tests/…
-
#run_on_changes(paths) ⇒ Object
Called on file(s) modifications that the Guard watches.
-
#start ⇒ Object
Call once when Guard starts.
Constructor Details
#initialize(watchers = [], options = {}) ⇒ Motion
Initialize a Guard.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/guard/motion.rb', line 14 def initialize(watchers = [], = {}) super @options = { :all_after_pass => true, :all_on_start => true, :keep_failed => true, :spec_paths => ["spec"] }.merge() @last_failed = false @failed_paths = [] @runner = Runner.new(@options) end |
Instance Method Details
#reload ⇒ Object
Called when ‘reload|r|z + enter` is pressed. This method should be mainly used for “reload” (really!) actions like reloading passenger/spork/bundler/…
38 39 40 |
# File 'lib/guard/motion.rb', line 38 def reload @failed_paths = [] end |
#run_all ⇒ Object
Called when just ‘enter` is pressed This method should be principally used for long action like running all specs/tests/…
45 46 47 48 49 50 51 52 53 |
# File 'lib/guard/motion.rb', line 45 def run_all passed = @runner.run unless @last_failed = !passed @failed_paths = [] else throw :task_has_failed end end |
#run_on_changes(paths) ⇒ Object
Called on file(s) modifications that the Guard watches.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/guard/motion.rb', line 58 def run_on_changes(paths) paths += @failed_paths if @options[:keep_failed] paths.uniq! if passed = @runner.run(paths) remove_failed(paths) # run all the specs if the run before this one failed if @last_failed && @options[:all_after_pass] @last_failed = false run_all end else @last_failed = true add_failed(paths) throw :task_has_failed end end |
#start ⇒ Object
Call once when Guard starts. Please override initialize method to init stuff.
30 31 32 33 |
# File 'lib/guard/motion.rb', line 30 def start UI.info "Guard::Motion is running" run_all if @options[:all_on_start] end |