2010-10-03 21:00:33 +00:00
|
|
|
module Guard
|
2011-08-30 19:13:51 +00:00
|
|
|
class Interactor
|
2011-05-06 17:29:24 +00:00
|
|
|
|
2011-09-01 21:24:45 +00:00
|
|
|
attr_reader :locked
|
|
|
|
|
2011-08-30 19:13:51 +00:00
|
|
|
def initialize
|
|
|
|
@locked = false
|
|
|
|
end
|
2011-08-17 08:07:30 +00:00
|
|
|
|
2011-08-30 19:13:51 +00:00
|
|
|
def start
|
2011-08-13 14:43:32 +00:00
|
|
|
return if ENV["GUARD_ENV"] == 'test'
|
2011-08-17 08:07:30 +00:00
|
|
|
Thread.new do
|
2011-08-29 19:25:58 +00:00
|
|
|
loop do
|
2011-08-30 19:13:51 +00:00
|
|
|
if (entry = $stdin.gets) && !@locked
|
2011-08-29 19:25:58 +00:00
|
|
|
entry.gsub! /\n/, ''
|
|
|
|
case entry
|
2011-08-30 19:13:51 +00:00
|
|
|
when 'stop', 'quit', 'exit', 's', 'q', 'e'
|
|
|
|
::Guard.stop
|
2011-08-29 19:25:58 +00:00
|
|
|
when 'reload', 'r', 'z'
|
2011-08-30 19:13:51 +00:00
|
|
|
::Guard.reload
|
|
|
|
when 'pause', 'p'
|
|
|
|
::Guard.pause
|
|
|
|
else
|
|
|
|
::Guard.run_all
|
2011-08-17 08:07:30 +00:00
|
|
|
end
|
2011-08-13 14:43:32 +00:00
|
|
|
end
|
2010-10-03 21:00:33 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-08-13 14:43:32 +00:00
|
|
|
|
2011-08-29 19:25:58 +00:00
|
|
|
def lock
|
2011-08-30 19:13:51 +00:00
|
|
|
@locked = true
|
2011-08-29 19:25:58 +00:00
|
|
|
end
|
2011-08-30 19:13:51 +00:00
|
|
|
|
2011-08-29 19:25:58 +00:00
|
|
|
def unlock
|
2011-08-30 19:13:51 +00:00
|
|
|
@locked = false
|
2011-08-17 08:07:30 +00:00
|
|
|
end
|
|
|
|
|
2010-10-03 21:00:33 +00:00
|
|
|
end
|
2011-05-06 17:29:24 +00:00
|
|
|
end
|