Permalink
Browse files

Rewrite for Guard 2.0

  • Loading branch information...
1 parent 079efa1 commit 6d24e9471a3f4606a6d8b689045a6ae343381189 @thibaudgg thibaudgg committed Oct 6, 2013
View
@@ -1,22 +1,10 @@
language: ruby
bundler_args: --without development
rvm:
- - 1.8.7
- 1.9.3
- 2.0.0
- - ruby-head
- - ree
- - jruby-18mode
- jruby-19mode
- - jruby-head
- - rbx-18mode
- rbx-19mode
-matrix:
- allow_failures:
- - rvm: rbx-18mode
- - rvm: rbx-19mode
- - rvm: ruby-head
- - rvm: jruby-head
notifications:
recipients:
- thibaud@thibaud.me
View
@@ -1,15 +1,8 @@
-source "https://rubygems.org"
+source 'https://rubygems.org'
gemspec
-gem 'rake'
-
group :development do
gem 'ruby_gntp'
- gem 'rb-fsevent'
gem 'guard-rspec'
end
-
-group :test do
- gem 'rspec'
-end
View
@@ -1,5 +1,5 @@
-guard 'rspec', :version => 2 do
+guard :rspec do
watch(%r{^spec/(.*)_spec.rb})
- watch(%r{^lib/(.*).rb}) { |m| "spec/#{m[1]}_spec.rb" }
+ watch(%r{^lib/(.*).rb}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
end
View
@@ -2,7 +2,7 @@
Pow guard allows to automatically & intelligently restart your applications (just by touching tmp/restart.txt)
-* Tested on Ruby 1.8.7, 1.9.3, 2.0.0, ree, rbx & jruby
+* Tested on Ruby 1.9.3, 2.0.0, rbx & jruby
Install
-------
@@ -32,7 +32,7 @@ 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.
+Please read [Guard doc](https://github.com/guard/guard#readme) for more info about Guardfile DSL.
### Rails app
@@ -53,8 +53,8 @@ end
### List of available options:
``` ruby
-:restart_on_start => true # Restart Pow on Guard start, default: false
-:restart_on_reload => false # Restart Pow on Guard reload, default: true
+restart_on_start: true # Restart Pow on Guard start, default: false
+restart_on_reload: false # Restart Pow on Guard reload, default: true
```
Development
View
@@ -1,5 +1,4 @@
-require 'bundler'
-Bundler::GemHelper.install_tasks
+require "bundler/gem_tasks"
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
View
@@ -1,26 +1,24 @@
-# -*- encoding: utf-8 -*-
-$:.push File.expand_path('../lib', __FILE__)
+# coding: utf-8
+lib = File.expand_path('../lib', __FILE__)
+$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
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.name = "guard-pow"
+ s.version = Guard::PowVersion::VERSION
+ s.author = "Thibaud Guillaume-Gentil"
+ s.email = "thibaud@thibaud.me"
+ s.summary = 'Guard plugin for Pow'
+ s.description = 'Guard::Pow automatically manage Pow applications restart'
+ s.homepage = 'http://rubygems.org/gems/guard-pow'
+ s.license = "MIT"
- s.required_rubygems_version = '>= 1.3.6'
- s.rubyforge_project = 'guard-pow'
-
- s.add_dependency 'guard', '>= 1.1'
+ s.files = `git ls-files`.split($/)
+ s.test_files = s.files.grep(%r{^spec/})
+ s.require_path = 'lib'
- s.add_development_dependency 'bundler'
+ s.add_dependency 'guard', '~> 2.0'
+ s.add_development_dependency 'bundler', ">= 1.4.0.rc.1"
+ s.add_development_dependency 'rake'
s.add_development_dependency 'rspec'
- s.add_development_dependency 'guard-rspec'
-
- s.files = Dir.glob('{lib}/**/*') + %w[LICENSE README.md]
- s.require_path = 'lib'
end
View
@@ -1,36 +1,32 @@
require 'guard'
-require 'guard/guard'
+require 'guard/plugin'
module Guard
- class Pow < Guard
+ class Pow < Plugin
+ require 'guard/pow/manager'
- autoload :Runner, 'guard/pow/runner'
- attr_accessor :runner
+ attr_accessor :manager
- def initialize(watchers = [], options = {})
+ def initialize(options = {})
super
@options = {
- :restart_on_start => false,
- :restart_on_reload => true
- }.update(options)
- @runner = Runner.new
+ restart_on_start: false,
+ restart_on_reload: true
+ }.merge(options)
+ @manager = Manager.new
end
def start
- runner.restart_pow if @options[:restart_on_start]
+ manager.restart if options[:restart_on_start]
end
def reload
- runner.restart_pow if @options[:restart_on_reload]
+ manager.restart if options[:restart_on_reload]
end
def run_on_changes(paths)
- runner.restart_pow
- end
-
- def stop
- true
+ manager.restart
end
end
-end
+end
View
@@ -0,0 +1,26 @@
+require 'fileutils'
+
+module Guard
+ class Pow
+ class Manager
+
+ def restart
+ _touch_tmp_restart
+ _notify "Pow restarted."
+ end
+
+ private
+
+ def _touch_tmp_restart
+ FileUtils.mkdir('tmp') unless File.directory?("tmp")
+ FileUtils.touch('tmp/restart.txt')
+ end
+
+ def _notify(message)
+ UI.info(message)
+ Notifier.notify(message, title: "Pow", image: :success)
+ end
+
+ end
+ end
+end
View
@@ -1,16 +0,0 @@
-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
@@ -1,41 +0,0 @@
-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 }.to 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 }.to 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 }.to change { File.mtime("tmp/restart.txt") }
- end
- end
- end
-
-end
View
@@ -1,41 +0,0 @@
-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 [], { :restart_on_start => true }
- end
- end
-
- describe "start" do
- it "should not restart pow by default" do
- subject.runner.should_not_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_changes" do
- it "should restart pow" do
- subject.runner.should_receive(:restart_pow)
- subject.run_on_changes(["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,46 @@
+require 'spec_helper'
+require 'fileutils'
+
+describe Guard::Pow::Manager do
+ let(:manager) { Guard::Pow::Manager.new }
+
+ before {
+ Guard::UI.stub(:info)
+ Guard::Notifier.stub(:notify)
+ }
+
+ describe "#restart_pow" do
+
+ context "without tmp dir" do
+ before { FileUtils.rm_rf('tmp') }
+
+ it "creates tmp/restart.txt" do
+ expect { manager.restart }.to change { File.file?("tmp/restart.txt") }.from(false).to(true)
+ end
+ end
+
+ context "with tmp dir" do
+ before {
+ FileUtils.mkdir 'tmp' unless File.directory?("tmp")
+ FileUtils.rm_rf('tmp/restart.txt')
+ }
+
+ it "creates tmp/restart.txt" do
+ expect { manager.restart }.to change { File.file?("tmp/restart.txt") }.from(false).to(true)
+ end
+ end
+
+ context "with tmp dir" do
+ before {
+ FileUtils.mkdir 'tmp' unless File.directory?("tmp")
+ FileUtils.touch('tmp/restart.txt')
+ sleep 1
+ }
+
+ it "touches tmp/restart.txt" do
+ expect { manager.restart }.to change { File.mtime("tmp/restart.txt") }
+ end
+ end
+ end
+
+end
Oops, something went wrong.

0 comments on commit 6d24e94

Please sign in to comment.