Permalink
Browse files

Inital commit

  • Loading branch information...
0 parents commit 629d8b273be28243078b2ef62cd3b4b6a821bf14 @thibaudgg thibaudgg committed Apr 8, 2011
Showing with 326 additions and 0 deletions.
  1. +13 −0 .gitignore
  2. +6 −0 .travis.yml
  3. +14 −0 Gemfile
  4. +5 −0 Guardfile
  5. +20 −0 LICENSE
  6. +57 −0 README.rdoc
  7. +21 −0 Rakefile
  8. +26 −0 guard-pow.gemspec
  9. +32 −0 lib/guard/pow.rb
  10. +16 −0 lib/guard/pow/runner.rb
  11. +11 −0 lib/guard/pow/templates/Guardfile
  12. +5 −0 lib/guard/pow/version.rb
  13. +41 −0 spec/guard/pow/runner_spec.rb
  14. +41 −0 spec/guard/pow_spec.rb
  15. +18 −0 spec/spec_helper.rb
@@ -0,0 +1,13 @@
+pkg/*
+*.gem
+.bundle
+Gemfile.lock
+tmp/*
+
+## MAC OS
+.DS_Store
+.Trashes
+.com.apple.timemachine.supported
+.fseventsd
+Desktop DB
+Desktop DF
@@ -0,0 +1,6 @@
+rvm:
+ - 1.8.7
+ - 1.9.2
+ - jruby
+ - rbx
+ - ree
14 Gemfile
@@ -0,0 +1,14 @@
+source "http://rubygems.org"
+
+gemspec
+
+require 'rbconfig'
+
+if Config::CONFIG['target_os'] =~ /darwin/i
+ gem 'rb-fsevent', '>= 0.3.9'
+ gem 'growl', '~> 1.0.3'
+end
+if Config::CONFIG['target_os'] =~ /linux/i
+ gem 'rb-inotify', '>= 0.5.1'
+ gem 'libnotify', '~> 0.1.3'
+end
@@ -0,0 +1,5 @@
+guard 'rspec', :version => 2 do
+ watch(%r{^spec/(.*)_spec.rb})
+ watch(%r{^lib/(.*).rb}) { |m| "spec/#{m[1]}_spec.rb" }
+ watch('spec/spec_helper.rb') { "spec" }
+end
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2011 Thibaud Guillaume-Gentil
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,57 @@
+= Guard::Pow
+
+Pow guard allows to automatically & intelligently restart your applications (just by touching tmp/restart.txt)
+
+- Tested on Ruby 1.8.6, 1.8.7 & 1.9.2.
+
+== Install
+
+Please be sure to have {Guard}[http://github.com/guard/guard] installed before continue.
+
+Install the gem:
+
+ gem install guard-pow
+
+Add it to your Gemfile (inside test group):
@bquorning

bquorning Jun 16, 2011

Inside test group? Don’t you mean inside development group?

@thibaudgg

thibaudgg Jun 17, 2011

Owner

Fixed here thanks (again!)

+
+ gem 'guard-pow'
+
+Add guard definition to your Guardfile with:
+
+ guard init pow
+
+== Usage
+
+Please read {Guard usage doc}[http://github.com/guard/guard#readme]
+
+== Guardfile
+
+Pow guard can be really be adapated to all kind of projects.
+Please read {Guard doc}[http://github.com/guard/guard#readme] for more info about Guardfile DSL.
+
+=== Rails app
+
+ guard 'pow' do
+ watch('.powrc')
+ watch('.powenv')
+ watch('.rvmrc')
+ watch('Gemfile')
+ watch('Gemfile.lock')
+ watch('config/application.rb')
+ watch('config/environment.rb')
+ watch(%r{^config/environments/.*\.rb$})
+ watch(%r{^config/initializers/.*\.rb$})
+ end
+
+
+== Development
+
+- Source hosted at {GitHub}[http://github.com/guard/guard-pow]
+- Report issues/Questions/Feature requests on {GitHub Issues}[http://github.com/guard/guard-pow/issues]
+
+Pull requests are very welcome! Make sure your patches are well tested. Please create a topic branch for every separate change
+you make.
+
+== Authors
+
+{Thibaud Guillaume-Gentil}[http://github.com/thibaudgg]
@@ -0,0 +1,21 @@
+require 'bundler'
+Bundler::GemHelper.install_tasks
+
+require 'rspec/core/rake_task'
+RSpec::Core::RakeTask.new(:spec)
+task :default => :spec
+
+namespace(:spec) do
+ desc "Run all specs on multiple ruby versions (requires rvm)"
+ task(:portability) do
+ %w[1.8.7 1.9.2].each do |version|
+ system <<-BASH
+ bash -c 'source ~/.rvm/scripts/rvm;
+ rvm #{version};
+ echo "--------- version #{version} ----------\n";
+ bundle install;
+ rake spec'
+ BASH
+ end
+ end
+end
@@ -0,0 +1,26 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path('../lib', __FILE__)
+require 'guard/pow/version'
+
+Gem::Specification.new do |s|
+ s.name = 'guard-pow'
+ s.version = Guard::PowVersion::VERSION
+ s.platform = Gem::Platform::RUBY
+ s.authors = ['Thibaud Guillaume-Gentil']
+ s.email = ['thibaud@thibaud.me']
+ s.homepage = 'http://rubygems.org/gems/guard-pow'
+ s.summary = 'Guard gem for Pow'
+ s.description = 'Guard::Pow automatically manage Pow applications restart'
+
+ s.required_rubygems_version = '>= 1.3.6'
+ s.rubyforge_project = 'guard-pow'
+
+ s.add_dependency 'guard', '>= 0.3.0'
+
+ s.add_development_dependency 'bundler', '~> 1.0.11'
+ s.add_development_dependency 'rspec', '~> 2.5.0'
+ s.add_development_dependency 'guard-rspec', '~> 0.2.0'
+
+ s.files = Dir.glob('{lib}/**/*') + %w[LICENSE README.rdoc]
+ s.require_path = 'lib'
+end
@@ -0,0 +1,32 @@
+require 'guard'
+require 'guard/guard'
+
+module Guard
+ class Pow < Guard
+
+ autoload :Runner, 'guard/pow/runner'
+ attr_accessor :runner
+
+ def initialize(watchers = [], options = {})
+ super
+ @runner = Runner.new
+ end
+
+ def start
+ runner.restart_pow
+ end
+
+ def reload
+ runner.restart_pow
+ end
+
+ def run_on_change(paths)
+ runner.restart_pow
+ end
+
+ def stop
+ true
+ end
+
+ end
+end
@@ -0,0 +1,16 @@
+require 'fileutils'
+
+module Guard
+ class Pow
+ class Runner
+
+ def restart_pow
+ FileUtils.mkdir 'tmp' unless File.directory?("tmp")
+ FileUtils.touch 'tmp/restart.txt'
+ UI.info "Pow restarted."
+ Notifier.notify("Pow restarted.", :title => "Pow", :image => :success)
+ end
+
+ end
+ end
+end
@@ -0,0 +1,11 @@
+guard 'pow' do
+ watch('.powrc')
+ watch('.powenv')
+ watch('.rvmrc')
+ watch('Gemfile')
+ watch('Gemfile.lock')
+ watch('config/application.rb')
+ watch('config/environment.rb')
+ watch(%r{^config/environments/.*\.rb$})
+ watch(%r{^config/initializers/.*\.rb$})
+end
@@ -0,0 +1,5 @@
+module Guard
+ module PowVersion
+ VERSION = "0.1.0"
+ end
+end
@@ -0,0 +1,41 @@
+require 'spec_helper'
+require 'fileutils'
+
+describe Guard::Pow::Runner do
+ subject { Guard::Pow::Runner.new }
+
+ describe "#restart_pow" do
+
+ context "without tmp dir" do
+ before(:each) { FileUtils.rm_rf('tmp') }
+
+ it "should create tmp/restart.txt" do
+ expect { subject.restart_pow }.should change { File.file?("tmp/restart.txt") }.from(false).to(true)
+ end
+ end
+
+ context "with tmp dir" do
+ before(:each) do
+ FileUtils.mkdir 'tmp' unless File.directory?("tmp")
+ FileUtils.rm_rf('tmp/restart.txt')
+ end
+
+ it "should create tmp/restart.txt" do
+ expect { subject.restart_pow }.should change { File.file?("tmp/restart.txt") }.from(false).to(true)
+ end
+ end
+
+ context "with tmp dir" do
+ before(:each) do
+ FileUtils.mkdir 'tmp' unless File.directory?("tmp")
+ FileUtils.touch('tmp/restart.txt')
+ sleep 1
+ end
+
+ it "should touch tmp/restart.txt" do
+ expect { subject.restart_pow }.should change { File.mtime("tmp/restart.txt") }
+ end
+ end
+ end
+
+end
@@ -0,0 +1,41 @@
+require 'spec_helper'
+
+describe Guard::Pow do
+ subject { Guard::Pow.new }
+
+ describe '#initialize' do
+ it 'should instanciate runner with option' do
+ Guard::Pow::Runner.should_receive(:new)
+ Guard::Pow.new [], { :bundler => false }
+ end
+ end
+
+ describe "start" do
+ it "should restart pow" do
+ subject.runner.should_receive(:restart_pow)
+ subject.start
+ end
+ end
+
+ describe "reload" do
+ it "should restart pow" do
+ subject.runner.should_receive(:restart_pow)
+ subject.reload
+ end
+ end
+
+ describe "run_on_change" do
+ it "should restart pow" do
+ subject.runner.should_receive(:restart_pow)
+ subject.run_on_change(["xxx"])
+ end
+ end
+
+ describe "stop" do
+ it "should do nothing'" do
+ subject.runner.should_not_receive(:restart_pow)
+ subject.stop
+ end
+ end
+
+end
@@ -0,0 +1,18 @@
+require 'rspec'
+require 'guard/pow'
+
+RSpec.configure do |config|
+ config.color_enabled = true
+ config.filter_run :focus => true
+ config.run_all_when_everything_filtered = true
+
+ config.before(:each) do
+ ENV["GUARD_ENV"] = 'test'
+ @lib_path = Pathname.new(File.expand_path('../../lib/', __FILE__))
+ end
+
+ config.after(:each) do
+ ENV["GUARD_ENV"] = nil
+ end
+
+end

0 comments on commit 629d8b2

Please sign in to comment.