diff --git a/guard-lacquer.gemspec b/guard-lacquer.gemspec index 9633001..30d75e8 100644 --- a/guard-lacquer.gemspec +++ b/guard-lacquer.gemspec @@ -7,8 +7,8 @@ Gem::Specification.new do |s| s.authors = ["John Bintz"] s.email = ["john@coswellproductions.com"] s.homepage = "" - s.summary = %q{TODO: Write a gem summary} - s.description = %q{TODO: Write a gem description} + s.summary = %q{Guard to run Varnish using Lacquer} + s.description = %q{Guard to run Varnish using Lacquer} s.rubyforge_project = "guard-lacquer" @@ -17,7 +17,7 @@ Gem::Specification.new do |s| s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ["lib"] - s.add_runtime_dependency 'lacquer' + s.add_runtime_dependency 'lacquer', '>= 0.5.0.beta' s.add_runtime_dependency 'guard' s.add_development_dependency 'rspec', '~> 2.6.0' diff --git a/images/varnish.png b/images/varnish.png new file mode 100644 index 0000000..22d58b9 Binary files /dev/null and b/images/varnish.png differ diff --git a/lib/guard-lacquer.rb b/lib/guard-lacquer.rb deleted file mode 100644 index 272d349..0000000 --- a/lib/guard-lacquer.rb +++ /dev/null @@ -1,2 +0,0 @@ -require 'guard/lacquer' - diff --git a/lib/guard/lacquer.rb b/lib/guard/lacquer.rb index 1978be9..b58a751 100644 --- a/lib/guard/lacquer.rb +++ b/lib/guard/lacquer.rb @@ -1,30 +1,44 @@ require 'guard' require 'guard/guard' -require 'lacquer' -require 'lacquer/varnishd' -p "made it" +require 'fileutils' module Guard - class Lacquer < Guard::Guard + class Lacquer < Guard + autoload :Varnishd, 'guard/lacquer/varnishd' + def initialize(watchers = [], options = {}) super - @backend = ::Lacquer::Varnishd.new( - :listen => "127.0.0.1:#{options[:port]}", - :storage => "file,tmp/cache/varnish.store,32M", - :backend => options[:backend], - :sbin_path => File.split(`which varnishd`).first, + @options = { + :port => 3001, + :backend => '127.0.0.1:3000', + :storage => 'file,tmp/cache/varnish.store,32M', + :sbin_path => File.split(`which varnishd`.strip).first, :pid_file => 'tmp/pids/varnish.pid' - ) + }.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 end def start + @backend.stop if @backend.running? @backend.start + + notify "Varnish started on port #{@options[:port]}, with backend #{@options[:backend]}." end def stop - @backend.start stop + @backend.stop + + notify("Until next time...", :title => 'guard-varnish') end def reload @@ -45,6 +59,11 @@ module Guard def run_on_deletion(paths) restart end + + private + def notify(message) + Notifier.notify(message, :title => 'guard-lacquer', :image => File.expand_path("../../../images/varnish.png", __FILE__)) + end end end diff --git a/lib/guard/lacquer/varnishd.rb b/lib/guard/lacquer/varnishd.rb new file mode 100644 index 0000000..c79776c --- /dev/null +++ b/lib/guard/lacquer/varnishd.rb @@ -0,0 +1,25 @@ +require 'lacquer' +require 'lacquer/varnishd' + +class Guard::Lacquer::Varnishd < ::Lacquer::Varnishd + attr_accessor :pid_file + + def self.root_path + Pathname.new(Dir.pwd) + end + + def self.env + ENV['RAILS_ENV'] || 'development' + end + + def initialize(options) + if options[:backend].split(':').first.empty? + options[:backend] = "127.0.0.1#{options[:backend]}" + end + self.pid_file = self.class.root_path.join(options[:pid_file]) + options[:listen] = "127.0.0.1:#{options[:port]}" + + super(Hash[options.collect { |k, v| [ k.to_s, v ] }]) + end +end + diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index df6bb5e..66ccdc4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1,4 @@ -require 'guard-lacquer' +require 'guard/lacquer' RSpec.configure do |c| c.mock_with :mocha