diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b14475..e358b89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## Master + +- Pull request [#137](https://github.com/guard/guard/pull/137): Fix interacting with tools like ruby-debug. ([@hron][] & [@netzpirat][]) + ## 0.7.0 - September 14, 2011 ## 0.7.0.rc1 - September 5, 2011 @@ -250,6 +254,7 @@ [@fnichol]: https://github.com/fnichol [@Gazer]: https://github.com/Gazer [@gix]: https://github.com/gix +[@hron]: https://github.com/hron [@hashrocketeer]: https://github.com/hashrocketeer [@ianwhite]: https://github.com/ianwhite [@indirect]: https://github.com/indirect diff --git a/lib/guard/interactor.rb b/lib/guard/interactor.rb index 1ef94ca..c6c56b2 100644 --- a/lib/guard/interactor.rb +++ b/lib/guard/interactor.rb @@ -4,6 +4,7 @@ module Guard # specific action upon them unless its locked. # # Currently the following actions are implemented: + # # - stop, quit, exit, s, q, e => Exit Guard # - reload, r, z => Reload Guard # - pause, p => Pause Guard @@ -11,6 +12,9 @@ module Guard # class Interactor + class LockException < Exception; end + class UnlockException < Exception; end + attr_reader :locked # Initialize the interactor in unlocked state. @@ -19,25 +23,31 @@ module Guard @locked = false end - # Start the interactor in a own thread. + # Start the interactor in its own thread. # def start return if ENV["GUARD_ENV"] == 'test' - Thread.new do + @thread = Thread.new do loop do - if (entry = $stdin.gets) && !@locked - entry.gsub! /\n/, '' - case entry - when 'stop', 'quit', 'exit', 's', 'q', 'e' - ::Guard.stop - when 'reload', 'r', 'z' - ::Guard.reload - when 'pause', 'p' - ::Guard.pause - else - ::Guard.run_all + begin + if !@locked && (entry = $stdin.gets) + entry.gsub! /\n/, '' + case entry + when 'stop', 'quit', 'exit', 's', 'q', 'e' + ::Guard.stop + when 'reload', 'r', 'z' + ::Guard.reload + when 'pause', 'p' + ::Guard.pause + else + ::Guard.run_all + end end + rescue LockException + lock + rescue UnlockException + unlock end end end @@ -46,13 +56,21 @@ module Guard # Lock the interactor. # def lock - @locked = true + if !@thread || @thread == Thread.current + @locked = true + else + @thread.raise(LockException) + end end # Unlock the interactor. # def unlock - @locked = false + if !@thread || @thread == Thread.current + @locked = false + else + @thread.raise(UnlockException) + end end end diff --git a/man/guard b/man/guard index b1a93f0..3260c45 100644 --- a/man/guard +++ b/man/guard @@ -17,6 +17,47 @@ . .nf +NAME +NAME +. +.fi +. +.IP "" 0 +. +.P +. +.P +. +.IP "" 4 +. +.nf + +
!DOCTYPE html
- ++ + + + +
<a href="#NAME">NAME</a>
+
+
+
+
+
++ + + + +
<li class='tl'>guard</li>
+<li class='tc'></li>
+<li class='tr'>guard</li>
+
+
+
+
+
++ + + + +
+ guard
+
.\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . @@ -242,6 +355,31 @@ This manual has been written by Remy Coutable. https://github.com/guard/guard
+ + +
<li class='tl'></li>
+<li class='tc'>September 2011</li>
+<li class='tr'>guard</li>
+
+
+
+
+
++ + + + +
+ +
+ +
<li class='tl'></li>
diff --git a/spec/guard/interactor_spec.rb b/spec/guard/interactor_spec.rb
index 09a17f2..72ced75 100644
--- a/spec/guard/interactor_spec.rb
+++ b/spec/guard/interactor_spec.rb
@@ -4,20 +4,22 @@ describe Guard::Interactor do
subject { Guard::Interactor.new }
describe "#initialize" do
- it "un-lock by default" do
+ it "unlocks the interactor by default" do
subject.locked.should be_false
end
end
describe "#lock" do
- it "locks" do
+ it "locks the interactor" do
+ subject.start
subject.lock
subject.locked.should be_true
end
end
describe "#unlock" do
- it "unlocks" do
+ it "unlocks the interactor" do
+ subject.start
subject.unlock
subject.locked.should be_false
end