Skip to content

Instantly share code, notes, and snippets.

@eccyan
Created September 18, 2013 08:03
Show Gist options
  • Save eccyan/6606055 to your computer and use it in GitHub Desktop.
Save eccyan/6606055 to your computer and use it in GitHub Desktop.
Guard で起動時に一度実行するプラグインを作る ref: http://qiita.com/eccyan/items/767e7cf43a1a24ccd025
require 'guard/guard'
notification :growl
module ::Guard
# 起動時に同期を行う Guard のプラグイン
class SyncronizeAll < Guard
def start
hostname="172.0.0.1"
username="eccyan"
application_path="/home/eccyan/devel/project/web"
current_path="/var/www/project/current"
# 同期を実行する
puts "Starting syncronize all to #{hostname}"
if result = `rsync -rvz --delete --omit-dir-times \
'#{application_path}/' '#{username}@#{hostname}':'#{current_path}'`
if $?.success?
::Guard::Notifier.notify("Syncronized", :title => 'Syncronize All')
else
::Guard::Notifier.notify("Failed", :title => 'Syncronize All',
:image => :failed)
end
end
# start は処理の成否を返さなければならない
$?.success?
end
end
end
group :your_group do
# 作成したプラグインを定義しておけば、初回起動時に実行される
guard :syncronize_all
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment