Use 'guard' instead of 'g', use parenthesis and don't explicitly return when not necessary

This commit is contained in:
Rémy Coutable 2010-11-26 00:58:36 +01:00
parent 3116b13f1b
commit 7f39a55fdf
4 changed files with 11 additions and 11 deletions

View File

@ -17,7 +17,7 @@ module Guard
@options = options @options = options
@listener = Listener.init @listener = Listener.init
@guards = [] @guards = []
return self self
end end
def start(options = {}) def start(options = {})
@ -41,7 +41,7 @@ module Guard
end end
UI.info "Guard is now watching at '#{Dir.pwd}'" UI.info "Guard is now watching at '#{Dir.pwd}'"
guards.each { |g| supervised_task(g, :start) } guards.each { |guard| supervised_task(guard, :start) }
listener.start listener.start
end end
end end
@ -68,9 +68,9 @@ module Guard
guard.send(task_to_supervise, *args) guard.send(task_to_supervise, *args)
rescue Exception rescue Exception
UI.error("#{guard.class.name} guard failed to achieve its <#{task_to_supervise.to_s}> command: #{$!}") UI.error("#{guard.class.name} guard failed to achieve its <#{task_to_supervise.to_s}> command: #{$!}")
::Guard.guards.delete guard ::Guard.guards.delete(guard)
UI.info("Guard #{guard.class.name} has just been fired") UI.info("Guard #{guard.class.name} has just been fired")
return $! $!
end end
def locate_guard(name) def locate_guard(name)

View File

@ -3,7 +3,7 @@ module Guard
def self.evaluate_guardfile def self.evaluate_guardfile
guardfile = "#{Dir.pwd}/Guardfile" guardfile = "#{Dir.pwd}/Guardfile"
if File.exists? guardfile if File.exists?(guardfile)
begin begin
dsl = new dsl = new
dsl.instance_eval(File.read(guardfile.to_s), guardfile.to_s, 1) dsl.instance_eval(File.read(guardfile.to_s), guardfile.to_s, 1)

View File

@ -14,9 +14,9 @@ module Guard
content = File.read('Guardfile') content = File.read('Guardfile')
guard = File.read("#{::Guard.locate_guard(name)}/lib/guard/#{name}/templates/Guardfile") guard = File.read("#{::Guard.locate_guard(name)}/lib/guard/#{name}/templates/Guardfile")
File.open('Guardfile', 'wb') do |f| File.open('Guardfile', 'wb') do |f|
f.puts content f.puts(content)
f.puts "" f.puts("")
f.puts guard f.puts(guard)
end end
::Guard::UI.info "#{name} guard added to Guardfile, feel free to edit it" ::Guard::UI.info "#{name} guard added to Guardfile, feel free to edit it"
end end

View File

@ -5,14 +5,14 @@ module Guard
# Run all (Ctrl-\) # Run all (Ctrl-\)
Signal.trap('QUIT') do Signal.trap('QUIT') do
::Guard.run do ::Guard.run do
::Guard.guards.each { |g| ::Guard.supervised_task g, :run_all } ::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :run_all) }
end end
end end
# Stop (Ctrl-C) # Stop (Ctrl-C)
Signal.trap('INT') do Signal.trap('INT') do
::Guard.listener.stop ::Guard.listener.stop
::Guard.guards.each { |g| ::Guard.supervised_task g, :stop } ::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :stop) }
UI.info "Bye bye...", :reset => true UI.info "Bye bye...", :reset => true
abort("\n") abort("\n")
end end
@ -20,7 +20,7 @@ module Guard
# Reload (Ctrl-Z) # Reload (Ctrl-Z)
Signal.trap('TSTP') do Signal.trap('TSTP') do
::Guard.run do ::Guard.run do
::Guard.guards.each { |g| ::Guard.supervised_task g, :reload } ::Guard.guards.each { |guard| ::Guard.supervised_task(guard, :reload) }
end end
end end
end end