Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Maher4Ever committed Jan 3, 2012
2 parents 1d0d1eb + 3b56ef7 commit c01bef5
Show file tree
Hide file tree
Showing 16 changed files with 206 additions and 61 deletions.
44 changes: 40 additions & 4 deletions CHANGELOG.md
@@ -1,3 +1,36 @@
## Master

### Bug fix

- [#213 & 214](https://github.com/guard/guard/issues/214): Fixes the "ERROR: No guards found in Guardfile" message wrongly displayed when running `guard list`. ([@pirukire][])

## 0.10.0 - 1 January, 2012

### Improvement

- Improved Readline constraints. ([@netzpirat][])
- Stop & start all guards on Guardfile reevaluation. ([@thibaudgg][])

### Bug fix

- Terminal keep-alive causing ERROR: Unknown command. ([@waldo][])

## 0.9.4 - December 25, 2011

### Improvement

- Add the ability to load user defined templates. ([@hawx][])

### Bug fix

- Fix guard-rspec notifications by using ENV variable to store Notifier.notifications. ([@thibaudgg][])

## 0.9.3 - December 23, 2011

### Improvement

- Fix terminal status after interrupting the Readline interactor. ([@Maher4Ever][])

## 0.9.2 - December 22, 2011

### Improvements
Expand All @@ -7,16 +40,16 @@

## 0.9.1 - December 19, 2011

### Bug fix
### Bug fixes

- Fix wrong `--no-vendor` option. ([@netzpirat][])
- [#195](https://github.com/guard/guard/issues/195): Empty watch directory prohibit Guard from running. (reported by [@madtrick][], fixed by [@netzpirat][]
- [#195](https://github.com/guard/guard/issues/195): Empty watch directory prohibit Guard from running. (reported by [@madtrick][], fixed by [@netzpirat][])

## 0.9.0 - December 19, 2011

### Bug fix
### Bug fixes

- [#173](https://github.com/guard/guard/issues/173): Cannot set the watch_all_modifications option. (reported by [@sutherland][], fixed by [@netzpirat][]
- [#173](https://github.com/guard/guard/issues/173): Cannot set the watch_all_modifications option. (reported by [@sutherland][], fixed by [@netzpirat][])
- Fix `guard init` when a guard name is given. ([@rymai][])

### Improvements
Expand Down Expand Up @@ -360,6 +393,7 @@
[@fnichol]: https://github.com/fnichol
[@Gazer]: https://github.com/Gazer
[@gix]: https://github.com/gix
[@hawx]: https://github.com/hawx
[@hron]: https://github.com/hron
[@hardipe]: https://github.com/hardipe
[@hashrocketeer]: https://github.com/hashrocketeer
Expand All @@ -382,6 +416,7 @@
[@niklas]: https://github.com/niklas
[@oliamb]: https://github.com/oliamb
[@pcreux]: https://github.com/pcreux
[@pirukire]: https://github.com/pirukire
[@rmm5t]: https://github.com/rmm5t
[@rymai]: https://github.com/rymai
[@scottdavis]: https://github.com/scottdavis
Expand All @@ -396,6 +431,7 @@
[@tpope]: https://github.com/tpope
[@uk-ar]: https://github.com/uk-ar
[@veged]: https://github.com/veged
[@waldo]: https://github.com/waldo
[@wereHamster]: https://github.com/wereHamster
[@yannlugrin]: https://github.com/yannlugrin
[@zonque]: https://github.com/zonque
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,4 +1,4 @@
Copyright (c) 2011 Thibaud Guillaume-Gentil
Copyright (c) 2009-2012 Thibaud Guillaume-Gentil

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
56 changes: 30 additions & 26 deletions README.md
Expand Up @@ -63,7 +63,8 @@ the time, try the [Rubygems Bundler](https://github.com/mpapis/rubygems-bundler)

### System notifications

You can configure Guard to make use of the following system notification libraries:
You can configure Guard to make use of the following system notification libraries, but it's strongly recommended
to use either Ruby GNTP, Libnotify or Notifu:

#### Ruby GNTP

Expand All @@ -87,31 +88,6 @@ group :development do
end
```

#### Growl

* Runs on Mac OS X
* Supports all [Growl](http://growl.info/) versions

The [growl](https://rubygems.org/gems/growl) gem is compatible with all versions of Growl and uses a command line tool
[growlnotify](http://growl.info/extras.php#growlnotify) that must be separately downloaded and installed. The version of
the command line tool must match your Growl version. The `growl` gem does **not** support multiple notification
channels.

You can download an installer for `growlnotify` from the [Growl download section](http://growl.info/downloads) or
install it with HomeBrew:

```bash
$ brew install growlnotify
```

To use `growl` you have to add it to your `Gemfile` and run bundler:

```ruby
group :development do
gem 'growl'
end
```

#### Libnotify

* Runs on Linux, FreeBSD, OpenBSD and Solaris
Expand Down Expand Up @@ -144,6 +120,26 @@ group :development do
end
```

#### Growl

* Runs on Mac OS X
* Supports all [Growl](http://growl.info/) versions

The [growl](https://rubygems.org/gems/growl) gem is compatible with all versions of Growl and uses a command line tool
[growlnotify](http://growl.info/extras.php#growlnotify) that must be separately downloaded and installed. The version of
the command line tool must match your Growl version. The `growl` gem does **not** support multiple notification
channels.

You have to download the installer for `growlnotify` from the [Growl download section](http://growl.info/downloads).

To use `growl` you have to add it to your `Gemfile` and run bundler:

```ruby
group :development do
gem 'growl'
end
```

#### GrowlNotify

* Runs on Mac OS X
Expand Down Expand Up @@ -218,6 +214,13 @@ In addition, the `init` task can be used to append a supplied Guard template fro
$ guard init <guard-name>
```

You can also define your own templates in `~/.guard/templates/` which can be appended in the same way to your existing
`Guardfile`:

```bash
$ guard init <template-name>
```

### Start

Just launch Guard inside your Ruby or Rails project with:
Expand Down Expand Up @@ -839,6 +842,7 @@ Pull requests are very welcome! Please try to follow these simple rules if appli

* Please create a topic branch for every separate change you make.
* Make sure your patches are well tested. All specs run with `rake spec:portability` must pass.
* On OS X you need to compile once rb-fsevent executable with `rake build_mac_exec`.
* Update the [Yard](http://yardoc.org/) documentation.
* Update the README.
* Update the CHANGELOG for noteworthy changes.
Expand Down
34 changes: 28 additions & 6 deletions lib/guard.rb
Expand Up @@ -17,6 +17,8 @@ module Guard

# The Guardfile template for `guard init`
GUARDFILE_TEMPLATE = File.expand_path('../guard/templates/Guardfile', __FILE__)
# The location of user defined templates
HOME_TEMPLATES = File.expand_path('~/.guard/templates')

class << self
attr_accessor :options, :interactor, :listener, :lock
Expand All @@ -26,7 +28,7 @@ class << self
#
# @see Guard::Guard.init
#
# @param [String] guard_name the name of the Guard to initialize
# @param [String] guard_name the name of the Guard or template to initialize
#
def initialize_template(guard_name = nil)
if !File.exist?('Guardfile')
Expand All @@ -38,8 +40,24 @@ def initialize_template(guard_name = nil)
end

if guard_name
guard_class = ::Guard.get_guard_class(guard_name)
guard_class.init(guard_name)
guard_class = ::Guard.get_guard_class(guard_name, true)
if guard_class
guard_class.init(guard_name)
elsif File.exist?(File.join(HOME_TEMPLATES, guard_name))
content = File.read('Guardfile')
template = File.read(File.join(HOME_TEMPLATES, guard_name))

File.open('Guardfile', 'wb') do |f|
f.puts(content)
f.puts("")
f.puts(template)
end

::Guard::UI.info "#{ guard_name } template added to Guardfile, feel free to edit it"
else
const_name = guard_name.downcase.gsub('-', '')
UI.error "Could not load 'guard/#{ guard_name.downcase }' or '~/.guard/templates/#{ guard_name.downcase }' or find class Guard::#{ const_name.capitalize }"
end
end
end

Expand Down Expand Up @@ -162,6 +180,7 @@ def start(options = {})
setup(options)

Dsl.evaluate_guardfile(options)
UI.error 'No guards found in Guardfile, please add at least one.' if ::Guard.guards.empty?

options[:notify] && ENV['GUARD_NOTIFY'] != 'false' ? Notifier.turn_on : Notifier.turn_off

Expand Down Expand Up @@ -432,9 +451,10 @@ def add_group(name, options = {})
# * `rspec` will find a class `Guard::RSpec`
#
# @param [String] name the name of the Guard
# @param [Boolean] fail_gracefully whether error messages should not be printed
# @return [Class, nil] the loaded class
#
def get_guard_class(name)
def get_guard_class(name, fail_gracefully=false)
name = name.to_s
try_require = false
const_name = name.gsub(/\/(.?)/) { "::#{ $1.upcase }" }.gsub(/(?:^|[_-])(.)/) { $1.upcase }
Expand All @@ -449,8 +469,10 @@ def get_guard_class(name)
UI.error "Could not find class Guard::#{ const_name.capitalize }"
end
rescue LoadError => loadError
UI.error "Could not load 'guard/#{ name.downcase }' or find class Guard::#{ const_name.capitalize }"
UI.error loadError.to_s
unless fail_gracefully
UI.error "Could not load 'guard/#{ name.downcase }' or find class Guard::#{ const_name.capitalize }"
UI.error loadError.to_s
end
end
end

Expand Down
29 changes: 19 additions & 10 deletions lib/guard/dsl.rb
Expand Up @@ -100,21 +100,30 @@ def evaluate_guardfile(options = {})

fetch_guardfile_contents
instance_eval_guardfile(guardfile_contents_with_user_config)

UI.error 'No guards found in Guardfile, please add at least one.' if !::Guard.guards.nil? && ::Guard.guards.empty?
end

# Re-evaluate the `Guardfile` to update the current Guard configuration.
#
def reevaluate_guardfile
::Guard.guards.clear
::Guard.reset_groups
::Guard::Notifier.notifications.clear
@@options.delete(:guardfile_contents)
Dsl.evaluate_guardfile(@@options)
msg = 'Guardfile has been re-evaluated.'
UI.info(msg)
Notifier.notify(msg)
::Guard.run do
# Stop each old guards
::Guard.run_on_guards do |guard|
::Guard.run_supervised_task(guard, :stop)
end
::Guard.guards.clear
::Guard.reset_groups
::Guard::Notifier.clear_notifications
@@options.delete(:guardfile_contents)
Dsl.evaluate_guardfile(@@options)
UI.error 'No guards found in Guardfile, please add at least one.' if ::Guard.guards.empty?
msg = 'Guardfile has been re-evaluated.'
UI.info(msg)
Notifier.notify(msg)
# Start each new guards
::Guard.run_on_guards do |guard|
::Guard.run_supervised_task(guard, :start)
end
end
end

# Evaluate the content of the `Guardfile`.
Expand Down
2 changes: 1 addition & 1 deletion lib/guard/dsl_describer.rb
Expand Up @@ -48,7 +48,7 @@ def list(options)
evaluate_guardfile(options)

installed_guards = guardfile_structure.inject([]) do |installed, group|
group[:guards].each { |guard| installed << guard[:name] } if group[:guards]
group[:guards].each { |guard| installed << guard[:name].to_s } if group[:guards]
installed
end

Expand Down
3 changes: 2 additions & 1 deletion lib/guard/interactor.rb
Expand Up @@ -79,7 +79,7 @@ def self.fabricate
def self.auto_detect
require 'readline'

if defined?(RbReadline) || defined?(JRUBY_VERSION) || !RbConfig::CONFIG['target_os'] =~ /darwin/i
if defined?(RbReadline) || defined?(JRUBY_VERSION) || RbConfig::CONFIG['target_os'] =~ /linux/i
ReadlineInteractor.new
else
SimpleInteractor.new
Expand All @@ -96,6 +96,7 @@ def start
# Kill interactor thread if not current
#
def stop
return if ENV['GUARD_ENV'] == 'test'
unless Thread.current == @thread
@thread.kill
end
Expand Down
3 changes: 2 additions & 1 deletion lib/guard/interactors/readline.rb
Expand Up @@ -15,7 +15,7 @@ class ReadlineInteractor < Interactor
def initialize
require 'readline'

unless defined?(RbReadline) || defined?(JRUBY_VERSION)
unless defined?(RbReadline) || defined?(JRUBY_VERSION) || RbConfig::CONFIG['target_os'] =~ /linux/i
::Guard::UI.info 'Please add rb-readline for proper Readline support.'
end

Expand Down Expand Up @@ -46,6 +46,7 @@ def stop
#
def read_line
while line = Readline.readline(prompt, true)
line.gsub!(/^\W*/, '')
if line =~ /^\s*$/ or Readline::HISTORY.to_a[-2] == line
Readline::HISTORY.pop
end
Expand Down
2 changes: 1 addition & 1 deletion lib/guard/interactors/simple.rb
Expand Up @@ -9,7 +9,7 @@ class SimpleInteractor < Interactor
#
def read_line
while line = $stdin.gets
process_input(line.chomp)
process_input(line.gsub(/^\W*/, '').chomp)
end
end

Expand Down
14 changes: 11 additions & 3 deletions lib/guard/notifier.rb
@@ -1,3 +1,5 @@
require 'yaml'

require 'rbconfig'
require 'pathname'
require 'guard/ui'
Expand Down Expand Up @@ -53,15 +55,21 @@ module Notifier
# @return [Hash] the notifications
#
def notifications
@notifications ||= []
ENV['GUARD_NOTIFICATIONS'] ? YAML::load(ENV['GUARD_NOTIFICATIONS']) : []
end

# Set the available notifications.
#
# @param [Array<Hash>] notifications the notifications
#
def notifications=(notifications)
@notifications = notifications
ENV['GUARD_NOTIFICATIONS'] = YAML::dump(notifications)
end

# Clear available notifications.
#
def clear_notifications
ENV['GUARD_NOTIFICATIONS'] = nil
end

# Turn notifications on. If no notifications are defined
Expand Down Expand Up @@ -107,7 +115,7 @@ def add_notification(name, options = { }, silent = false)
return turn_off if name == :off

if NOTIFIERS.has_key?(name) && NOTIFIERS[name].available?(silent)
notifications << { :name => name, :options => options }
self.notifications = notifications << { :name => name, :options => options }
true
else
false
Expand Down
2 changes: 1 addition & 1 deletion lib/guard/version.rb
@@ -1,6 +1,6 @@
module Guard
unless defined? Guard::VERSION
# The current gem version of Guard
VERSION = '0.9.2'
VERSION = '0.10.0'
end
end

0 comments on commit c01bef5

Please sign in to comment.