Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Various tweaks #77

Merged
merged 6 commits into from

2 participants

@mislav

This branch contains various small tweaks I've done to Guard. The most important is 17a654b for which I forgot to send a pull request in time for the the 0.4.0 release. Others are for you to review and cherry-pick if wanted

mislav added some commits
@mislav mislav fix grammar in gem summary & description d5a5fa1
@mislav mislav gemspec: avoid adding the "lib/" directory to load path
Simply reading the gemspec shouldn't activate the gem by adding its
files to the load path.
03aa0b0
@mislav mislav change gem "homepage" property to the GitHub project 29f671b
@mislav mislav include CHANGELOG in the gem 9d63f1a
@mislav mislav refactor `get_guard_class` to first try the constant and fallback to …
…require

This enables defining inline guard handlers to override ones present in gems,
e.g. you could define an inline Guard::RSpec handler and have guard use that
instead of first trying to load 'guard/rspec' from the 'guard-rspec' gem.

Also gets rid of the ill-named method `try_to_load_gem`. Handlers are simply
found in the $LOAD_PATH and don't have to necessarily come from gems.
17a654b
@mislav mislav skip version comparison if Gem::Version is not available
This decouples Guard from RubyGems
2997ed6
@thibaudgg
Owner

Awesome, thanks!

@thibaudgg thibaudgg merged commit 2997ed6 into guard:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 7, 2011
  1. @mislav
  2. @mislav

    gemspec: avoid adding the "lib/" directory to load path

    mislav authored
    Simply reading the gemspec shouldn't activate the gem by adding its
    files to the load path.
  3. @mislav
  4. @mislav

    include CHANGELOG in the gem

    mislav authored
  5. @mislav

    refactor `get_guard_class` to first try the constant and fallback to …

    mislav authored
    …require
    
    This enables defining inline guard handlers to override ones present in gems,
    e.g. you could define an inline Guard::RSpec handler and have guard use that
    instead of first trying to load 'guard/rspec' from the 'guard-rspec' gem.
    
    Also gets rid of the ill-named method `try_to_load_gem`. Handlers are simply
    found in the $LOAD_PATH and don't have to necessarily come from gems.
  6. @mislav

    skip version comparison if Gem::Version is not available

    mislav authored
    This decouples Guard from RubyGems
This page is out of date. Refresh to see the latest.
View
11 guard.gemspec
@@ -1,6 +1,5 @@
# -*- encoding: utf-8 -*-
-$:.push File.expand_path('../lib', __FILE__)
-require 'guard/version'
+Kernel.load File.expand_path('../lib/guard/version.rb', __FILE__)
Gem::Specification.new do |s|
s.name = 'guard'
@@ -8,9 +7,9 @@ Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.authors = ['Thibaud Guillaume-Gentil']
s.email = ['thibaud@thibaud.me']
- s.homepage = 'http://rubygems.org/gems/guard'
- s.summary = 'Guard keep an eye on your files modifications.'
- s.description = 'Guard is a command line tool to easily handle events on files modifications.'
+ s.homepage = 'https://github.com/guard/guard'
+ s.summary = 'Guard keeps an eye on your file modifications'
+ s.description = 'Guard is a command line tool to easily handle events on file system modifications.'
s.required_rubygems_version = '>= 1.3.6'
s.rubyforge_project = 'guard'
@@ -21,7 +20,7 @@ Gem::Specification.new do |s|
s.add_dependency 'thor', '~> 0.14.6'
- s.files = Dir.glob('{bin,images,lib}/**/*') + %w[LICENSE README.md]
+ s.files = Dir.glob('{bin,images,lib}/**/*') + %w[LICENSE README.md CHANGELOG.md]
s.executable = 'guard'
s.require_path = 'lib'
end
View
24 lib/guard.rb
@@ -81,15 +81,21 @@ def add_guard(name, watchers = [], options = {})
end
def get_guard_class(name)
- try_to_load_gem(name)
- self.const_get(self.constants.find { |klass_name| klass_name.to_s.downcase == name.to_s.downcase.gsub('-', '') })
- rescue TypeError
- UI.error "Could not find load find gem 'guard-#{name}' or find class Guard::#{name}"
- end
-
- def try_to_load_gem(name)
- require "guard/#{name.to_s.downcase}"
- rescue LoadError
+ try_require = false
+ const_name = name.to_s.downcase.gsub('-', '')
+ begin
+ require "guard/#{name.downcase}" if try_require
+ self.const_get(self.constants.find {|c| c.to_s.downcase == const_name })
+ rescue TypeError
+ unless try_require
+ try_require = true
+ retry
+ else
+ UI.error "Could not find class Guard::#{const_name.capitalize}"
+ end
+ rescue LoadError
+ UI.error "Could not load 'guard/#{name.downcase}' or find class Guard::#{const_name.capitalize}"
+ end
end
def locate_guard(name)
View
7 lib/guard/listeners/darwin.rb
@@ -23,10 +23,13 @@ def stop
def self.usable?
require 'rb-fsevent'
- if !defined?(FSEvent::VERSION) || Gem::Version.new(FSEvent::VERSION) < Gem::Version.new('0.4.0')
+ if !defined?(FSEvent::VERSION) || (defined?(Gem::Version) &&
+ Gem::Version.new(FSEvent::VERSION) < Gem::Version.new('0.4.0'))
UI.info "Please update rb-fsevent (>= 0.4.0)"
+ false
+ else
+ true
end
- true
rescue LoadError
UI.info "Please install rb-fsevent gem for Mac OSX FSEvents support"
false
View
7 lib/guard/listeners/linux.rb
@@ -24,10 +24,13 @@ def stop
def self.usable?
require 'rb-inotify'
- if !defined?(INotify::VERSION) || Gem::Version.new(INotify::VERSION.join('.')) < Gem::Version.new('0.8.5')
+ if !defined?(INotify::VERSION) || (defined?(Gem::Version) &&
+ Gem::Version.new(INotify::VERSION.join('.')) < Gem::Version.new('0.8.5'))
UI.info "Please update rb-inotify (>= 0.8.5)"
+ false
+ else
+ true
end
- true
rescue LoadError
UI.info "Please install rb-inotify gem for Linux inotify support"
false
View
2  lib/guard/version.rb
@@ -1,3 +1,3 @@
module Guard
- VERSION = "0.4.0"
+ VERSION = "0.4.0" unless defined? VERSION
end
View
43 spec/guard_spec.rb
@@ -1,4 +1,5 @@
require 'spec_helper'
+require 'guard/guard'
describe Guard do
@@ -41,35 +42,41 @@
end
describe ".get_guard_class" do
+ after do
+ [:Classname, :DashedClassName, :Inline].each do |const|
+ Guard.send(:remove_const, const) rescue nil
+ end
+ end
+
it "reports an error if the class is not found" do
::Guard::UI.should_receive(:error)
Guard.get_guard_class('notAGuardClass')
end
context 'with a nested Guard class' do
- it "returns the Guard class when passed a Symbol" do
- Guard.should_receive(:try_to_load_gem) { |classname|
- classname.should == :classname
+ it "resolves the Guard class from string" do
+ Guard.should_receive(:require) { |classname|
+ classname.should == 'guard/classname'
class Guard::Classname
end
}
- Guard.get_guard_class(:classname).should == Guard::Classname
+ Guard.get_guard_class('classname').should == Guard::Classname
end
-
- it "returns the Guard class when passed a String" do
- Guard.should_receive(:try_to_load_gem) { |classname|
- classname.should == 'classname'
+
+ it "resolves the Guard class from symbol" do
+ Guard.should_receive(:require) { |classname|
+ classname.should == 'guard/classname'
class Guard::Classname
end
}
- Guard.get_guard_class('classname').should == Guard::Classname
+ Guard.get_guard_class(:classname).should == Guard::Classname
end
end
context 'with a name with dashes' do
it "returns the Guard class" do
- Guard.should_receive(:try_to_load_gem) { |classname|
- classname.should == 'dashed-class-name'
+ Guard.should_receive(:require) { |classname|
+ classname.should == 'guard/dashed-class-name'
class Guard::DashedClassName
end
}
@@ -84,23 +91,11 @@ class Inline < Guard
end
end
+ Guard.should_not_receive(:require)
Guard.get_guard_class('inline').should == Guard::Inline
end
end
end
-
- describe ".try_to_load_gem" do
- class Guard::Classname
- end
-
- it "reports an error if the class is not found" do
- Guard.get_guard_class('classname').should be_true
- end
-
- it "reports an error if the class is not found" do
- Guard.get_guard_class(:classname).should be_true
- end
- end
describe ".locate_guard" do
it "returns the path of a Guard gem" do
Something went wrong with that request. Please try again.