Merge pull request #58 from nicksieger/interactor-module-methods
Extract code from signal handlers into methods
This commit is contained in:
commit
d6d9dd9e75
@ -1,29 +1,41 @@
|
|||||||
module Guard
|
module Guard
|
||||||
module Interactor
|
module Interactor
|
||||||
|
extend self
|
||||||
|
|
||||||
|
def run_all
|
||||||
|
::Guard.run do
|
||||||
|
::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :run_all) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def stop
|
||||||
|
UI.info "Bye bye...", :reset => true
|
||||||
|
::Guard.listener.stop
|
||||||
|
::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :stop) }
|
||||||
|
abort("\n")
|
||||||
|
end
|
||||||
|
|
||||||
|
def reload
|
||||||
|
::Guard.run do
|
||||||
|
::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :reload) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def self.init_signal_traps
|
def self.init_signal_traps
|
||||||
# Run all (Ctrl-\)
|
# Run all (Ctrl-\)
|
||||||
Signal.trap('QUIT') do
|
Signal.trap('QUIT') do
|
||||||
::Guard.run do
|
run_all
|
||||||
::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :run_all) }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Stop (Ctrl-C)
|
# Stop (Ctrl-C)
|
||||||
Signal.trap('INT') do
|
Signal.trap('INT') do
|
||||||
UI.info "Bye bye...", :reset => true
|
stop
|
||||||
::Guard.listener.stop
|
|
||||||
::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :stop) }
|
|
||||||
abort("\n")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Reload (Ctrl-Z)
|
# Reload (Ctrl-Z)
|
||||||
Signal.trap('TSTP') do
|
Signal.trap('TSTP') do
|
||||||
::Guard.run do
|
reload
|
||||||
::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :reload) }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
25
spec/guard/interactor_spec.rb
Normal file
25
spec/guard/interactor_spec.rb
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Guard::Interactor do
|
||||||
|
subject { Guard::Interactor }
|
||||||
|
let(:guard) { mock "guard" }
|
||||||
|
before :each do
|
||||||
|
Guard.stub!(:guards).and_return([guard])
|
||||||
|
Guard.stub!(:listener).and_return(mock(:start => nil, :stop => nil))
|
||||||
|
end
|
||||||
|
|
||||||
|
it ".run_all should send :run_all to all guards" do
|
||||||
|
guard.should_receive(:run_all)
|
||||||
|
subject.run_all
|
||||||
|
end
|
||||||
|
|
||||||
|
it ".stop should send :stop to all guards" do
|
||||||
|
guard.should_receive(:stop)
|
||||||
|
lambda { subject.stop }.should raise_error(SystemExit)
|
||||||
|
end
|
||||||
|
|
||||||
|
it ".reload should send :reload to all guards" do
|
||||||
|
guard.should_receive(:reload)
|
||||||
|
subject.reload
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user