2011-09-28 15:22:05 +00:00
|
|
|
require 'guard'
|
|
|
|
require 'guard/guard'
|
|
|
|
|
2011-09-28 17:15:01 +00:00
|
|
|
require 'fileutils'
|
2011-09-28 15:22:05 +00:00
|
|
|
|
|
|
|
module Guard
|
2011-09-28 17:15:01 +00:00
|
|
|
class Lacquer < Guard
|
|
|
|
autoload :Varnishd, 'guard/lacquer/varnishd'
|
|
|
|
|
2011-09-28 15:22:05 +00:00
|
|
|
def initialize(watchers = [], options = {})
|
|
|
|
super
|
|
|
|
|
2011-09-28 17:15:01 +00:00
|
|
|
@options = {
|
|
|
|
:port => 3001,
|
|
|
|
:backend => '127.0.0.1:3000',
|
|
|
|
:storage => 'file,tmp/cache/varnish.store,32M',
|
|
|
|
:sbin_path => File.split(`which varnishd`.strip).first,
|
2011-09-28 15:22:05 +00:00
|
|
|
:pid_file => 'tmp/pids/varnish.pid'
|
2011-09-28 17:15:01 +00:00
|
|
|
}.merge(options)
|
|
|
|
|
|
|
|
@backend = Varnishd.new(@options)
|
|
|
|
|
|
|
|
if !File.file?(varnish_erb = 'config/varnish.vcl.erb')
|
|
|
|
UI.info "No config/varnish.vcl.erb found, copying default from Lacquer..."
|
|
|
|
|
|
|
|
FileUtils.mkdir_p File.split(varnish_erb).first
|
|
|
|
FileUtils.cp Gem.find_files('generators/lacquer/templates/varnish.vcl.erb').first, varnish_erb
|
|
|
|
end
|
2011-09-28 15:22:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def start
|
2011-09-28 17:15:01 +00:00
|
|
|
@backend.stop if @backend.running?
|
2011-09-28 15:22:05 +00:00
|
|
|
@backend.start
|
2011-09-28 17:15:01 +00:00
|
|
|
|
|
|
|
notify "Varnish started on port #{@options[:port]}, with backend #{@options[:backend]}."
|
2011-09-28 15:22:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def stop
|
2011-09-28 17:15:01 +00:00
|
|
|
@backend.stop
|
|
|
|
|
2011-09-28 17:28:19 +00:00
|
|
|
notify "Until next time..."
|
2011-09-28 15:22:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def reload
|
2011-09-28 19:25:08 +00:00
|
|
|
true
|
2011-09-28 15:22:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def run_all
|
2011-09-28 19:25:08 +00:00
|
|
|
stop
|
|
|
|
start
|
2011-09-28 15:22:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Called on file(s) modifications
|
|
|
|
def run_on_change(paths)
|
2011-09-28 19:25:08 +00:00
|
|
|
run_all
|
2011-09-28 15:22:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Called on file(s) deletions
|
|
|
|
def run_on_deletion(paths)
|
2011-09-28 19:25:08 +00:00
|
|
|
run_all
|
2011-09-28 15:22:05 +00:00
|
|
|
end
|
2011-09-28 17:15:01 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
def notify(message)
|
|
|
|
Notifier.notify(message, :title => 'guard-lacquer', :image => File.expand_path("../../../images/varnish.png", __FILE__))
|
|
|
|
end
|
2011-09-28 15:22:05 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|