Guard gem: 运行 一些启动或关闭时的代码?
Guard gem: run some code at startup or shutdown?
有没有办法在 Guard gem? 的启动或关闭时 运行 一些代码?
我想在开始或结束开发会话时自动执行一些维护任务。
看看这个:http://devblog.avdi.org/2011/06/15/a-guardfile-for-redis/
基本上你可以在你的 guardfile 中创建一个 "Inline" Guard,比如:
require 'guard/compat/plugin'
# the double-colons below are *required* for inline Guards!!!
module ::Guard
class MyPlugin < Plugin
def start
puts "Starting server"
end
# Called when `stop|quit|exit|s|q|e + enter` is pressed (when Guard quits).
#
# @raise [:task_has_failed] when stop has failed
# @return [Object] the task result
#
def stop
puts "Stopping server"
end
# Called when `reload|r|z + enter` is pressed.
# This method should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/...
#
# @raise [:task_has_failed] when reload has failed
# @return [Object] the task result
#
def reload
stop
start
end
end
end
# Startup the inline plugin
guard('my-plugin')
... other Guard config follows ...
有没有办法在 Guard gem? 的启动或关闭时 运行 一些代码?
我想在开始或结束开发会话时自动执行一些维护任务。
看看这个:http://devblog.avdi.org/2011/06/15/a-guardfile-for-redis/
基本上你可以在你的 guardfile 中创建一个 "Inline" Guard,比如:
require 'guard/compat/plugin'
# the double-colons below are *required* for inline Guards!!!
module ::Guard
class MyPlugin < Plugin
def start
puts "Starting server"
end
# Called when `stop|quit|exit|s|q|e + enter` is pressed (when Guard quits).
#
# @raise [:task_has_failed] when stop has failed
# @return [Object] the task result
#
def stop
puts "Stopping server"
end
# Called when `reload|r|z + enter` is pressed.
# This method should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/...
#
# @raise [:task_has_failed] when reload has failed
# @return [Object] the task result
#
def reload
stop
start
end
end
end
# Startup the inline plugin
guard('my-plugin')
... other Guard config follows ...