guard 0.2.0.beta.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +29 -7
- data/lib/guard.rb +13 -7
- data/lib/guard/interactor.rb +3 -3
- data/lib/guard/listeners/linux.rb +19 -15
- data/lib/guard/notifier.rb +26 -9
- data/lib/guard/version.rb +1 -1
- metadata +23 -41
data/README.rdoc
CHANGED
@@ -4,14 +4,14 @@ Guard is a command line tool to easly handle events on files modifications.
|
|
4
4
|
|
5
5
|
== Features
|
6
6
|
|
7
|
-
- FSEvent support on Mac OS X 10.5+ (without RubyCocoa!,
|
8
|
-
- Inotify support on Linux (
|
7
|
+
- {FSEvent}[http://en.wikipedia.org/wiki/FSEvents] support on Mac OS X 10.5+ (without RubyCocoa!, {rb-fsevent gem, >= 0.3.2}[https://rubygems.org/gems/rb-fsevent] required)
|
8
|
+
- {Inotify}[http://en.wikipedia.org/wiki/Inotify] support on Linux ({rb-inotify gem, >= 0.5.1}[https://rubygems.org/gems/rb-inotify] required)
|
9
9
|
- Polling for others (help us to support more systems)
|
10
10
|
- Super fast change detection (when polling not used)
|
11
11
|
- Automatic files modifications detection (even new files are detected)
|
12
|
-
- Growl notification (
|
13
|
-
- Libnotify notification
|
14
|
-
- Tested on Ruby 1.8.7 & 1.9.2
|
12
|
+
- Growl notification ({growlnotify}[http://growl.info/documentation/growlnotify.php] & {growl gem}[https://rubygems.org/gems/growl] required)
|
13
|
+
- Libnotify notification ({libnotify gem}[https://rubygems.org/gems/libnotify] required)
|
14
|
+
- Tested on Ruby 1.8.6, 1.8.7 & 1.9.2
|
15
15
|
|
16
16
|
== Install
|
17
17
|
|
@@ -29,6 +29,26 @@ Generate an empty Guardfile with:
|
|
29
29
|
|
30
30
|
Add guard(s) you need (see available guards below)
|
31
31
|
|
32
|
+
=== On Mac OS X
|
33
|
+
|
34
|
+
Install rb-fsevent for {FSEvent}[http://en.wikipedia.org/wiki/FSEvents] support
|
35
|
+
|
36
|
+
gem install rb-fsevent
|
37
|
+
|
38
|
+
Install growl for Growl notification support
|
39
|
+
|
40
|
+
gem install growl
|
41
|
+
|
42
|
+
=== On Linux
|
43
|
+
|
44
|
+
Install rb-inotify for {inotify}[http://en.wikipedia.org/wiki/Inotify] support
|
45
|
+
|
46
|
+
gem install rb-inotify
|
47
|
+
|
48
|
+
Install libnotify for libonity notification support
|
49
|
+
|
50
|
+
gem install libnotify
|
51
|
+
|
32
52
|
== Usage
|
33
53
|
|
34
54
|
Just launch Guard inside your ruby/rails project with:
|
@@ -52,14 +72,16 @@ Signal handlers are used to interact with Guard:
|
|
52
72
|
== Available Guards
|
53
73
|
|
54
74
|
- {guard-rspec}[http://github.com/guard/guard-rspec]
|
75
|
+
- {guard-test}[http://github.com/guard/guard-test]
|
76
|
+
- {guard-minitest}[http://github.com/guard/guard-minitest]
|
55
77
|
- {guard-livereload}[http://github.com/guard/guard-livereload]
|
78
|
+
- {guard-sass}[http://github.com/guard/guard-sass]
|
79
|
+
- {guard-shell}[http://github.com/guard/guard-shell]
|
56
80
|
|
57
81
|
guard ideas:
|
58
82
|
|
59
83
|
- guard-spork
|
60
84
|
- guard-cucumber
|
61
|
-
- guard-test
|
62
|
-
- guard-sass
|
63
85
|
- guard-bundler
|
64
86
|
- others ideas?
|
65
87
|
|
data/lib/guard.rb
CHANGED
@@ -33,7 +33,7 @@ module Guard
|
|
33
33
|
end
|
34
34
|
|
35
35
|
UI.info "Guard is now watching at '#{Dir.pwd}'"
|
36
|
-
guards.each
|
36
|
+
guards.each { |g| g.start }
|
37
37
|
listener.start
|
38
38
|
end
|
39
39
|
end
|
@@ -45,22 +45,28 @@ module Guard
|
|
45
45
|
|
46
46
|
def get_guard_class(name)
|
47
47
|
require "guard/#{name.downcase}"
|
48
|
-
|
48
|
+
klasses = []
|
49
|
+
ObjectSpace.each_object(Class) do |klass|
|
50
|
+
klasses << klass if klass.to_s.downcase.match "^guard::#{name.downcase}"
|
51
|
+
end
|
52
|
+
klasses.first
|
49
53
|
rescue LoadError
|
50
54
|
UI.error "Could not find gem 'guard-#{name}' in the current Gemfile."
|
51
55
|
end
|
52
56
|
|
53
57
|
def locate_guard(name)
|
54
|
-
|
55
|
-
spec.full_gem_path
|
58
|
+
`gem open guard-#{name} --latest --command echo`
|
56
59
|
rescue
|
57
|
-
UI.error "Could not find
|
60
|
+
UI.error "Could not find 'guard-#{name}' gem path."
|
58
61
|
end
|
59
62
|
|
60
63
|
def run
|
61
64
|
listener.stop
|
62
|
-
UI.
|
63
|
-
|
65
|
+
UI.clear if options[:clear]
|
66
|
+
begin
|
67
|
+
yield
|
68
|
+
rescue Interrupt
|
69
|
+
end
|
64
70
|
listener.start
|
65
71
|
end
|
66
72
|
|
data/lib/guard/interactor.rb
CHANGED
@@ -5,14 +5,14 @@ module Guard
|
|
5
5
|
# Run all (Ctrl-\)
|
6
6
|
Signal.trap('QUIT') do
|
7
7
|
::Guard.run do
|
8
|
-
::Guard.guards.each
|
8
|
+
::Guard.guards.each { |g| g.run_all }
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
12
|
# Stop (Ctrl-C)
|
13
13
|
Signal.trap('INT') do
|
14
14
|
::Guard.listener.stop
|
15
|
-
if ::Guard.guards.all?
|
15
|
+
if ::Guard.guards.all? { |g| g.stop }
|
16
16
|
UI.info "Bye bye...", :reset => true
|
17
17
|
abort("\n")
|
18
18
|
else
|
@@ -23,7 +23,7 @@ module Guard
|
|
23
23
|
# Reload (Ctrl-Z)
|
24
24
|
Signal.trap('TSTP') do
|
25
25
|
::Guard.run do
|
26
|
-
::Guard.guards.each
|
26
|
+
::Guard.guards.each { |g| g.reload }
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module Guard
|
2
2
|
class Linux < Listener
|
3
3
|
attr_reader :inotify, :files, :latency, :callback
|
4
|
-
|
4
|
+
|
5
5
|
def initialize
|
6
6
|
@inotify = INotify::Notifier.new
|
7
7
|
@files = []
|
8
8
|
@latency = 0.5
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def on_change(&callback)
|
12
12
|
@callback = callback
|
13
13
|
inotify.watch(Dir.pwd, :recursive, :attrib, :modify, :create) do |event|
|
@@ -15,21 +15,22 @@ module Guard
|
|
15
15
|
@files << event.absolute_name
|
16
16
|
end
|
17
17
|
end
|
18
|
+
rescue Interrupt
|
18
19
|
end
|
19
|
-
|
20
|
+
|
20
21
|
def start
|
21
22
|
@stop = false
|
22
23
|
watch_change
|
23
24
|
end
|
24
|
-
|
25
|
+
|
25
26
|
def stop
|
26
27
|
@stop = true
|
27
28
|
inotify.stop
|
28
29
|
end
|
29
|
-
|
30
|
+
|
30
31
|
def self.usable?
|
31
32
|
require 'rb-inotify'
|
32
|
-
if !defined?(INotify::VERSION) || Gem::Version.new(INotify::VERSION) < Gem::Version.new('0.5.1')
|
33
|
+
if !defined?(INotify::VERSION) || Gem::Version.new(INotify::VERSION.join('.')) < Gem::Version.new('0.5.1')
|
33
34
|
UI.info "Please update rb-inotify (>= 0.5.1)"
|
34
35
|
false
|
35
36
|
else
|
@@ -39,20 +40,23 @@ module Guard
|
|
39
40
|
UI.info "Please install rb-inotify gem for Linux inotify support"
|
40
41
|
false
|
41
42
|
end
|
42
|
-
|
43
|
+
|
43
44
|
private
|
44
|
-
|
45
|
+
|
45
46
|
def watch_change
|
46
47
|
while !@stop
|
47
|
-
inotify.
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
if Config::CONFIG['build'] =~ /java/ || IO.select([inotify.to_io], [], [], latency)
|
49
|
+
inotify.process
|
50
|
+
|
51
|
+
unless files.empty?
|
52
|
+
files.map! { |file| file.gsub("#{Dir.pwd}/", '') }
|
53
|
+
callback.call(files)
|
54
|
+
files.clear
|
55
|
+
end
|
56
|
+
sleep latency
|
52
57
|
end
|
53
|
-
sleep latency
|
54
58
|
end
|
55
59
|
end
|
56
|
-
|
60
|
+
|
57
61
|
end
|
58
62
|
end
|
data/lib/guard/notifier.rb
CHANGED
@@ -1,13 +1,6 @@
|
|
1
1
|
require 'rbconfig'
|
2
2
|
require 'pathname'
|
3
3
|
|
4
|
-
case Config::CONFIG['target_os']
|
5
|
-
when /darwin/i
|
6
|
-
require 'growl'
|
7
|
-
when /linux/i
|
8
|
-
require 'libnotify'
|
9
|
-
end
|
10
|
-
|
11
4
|
module Guard
|
12
5
|
module Notifier
|
13
6
|
|
@@ -17,9 +10,13 @@ module Guard
|
|
17
10
|
title = options[:title] || "Guard"
|
18
11
|
case Config::CONFIG['target_os']
|
19
12
|
when /darwin/i
|
20
|
-
|
13
|
+
if growl_installed?
|
14
|
+
Growl.notify message, :title => title, :icon => image_path(image), :name => "Guard"
|
15
|
+
end
|
21
16
|
when /linux/i
|
22
|
-
|
17
|
+
if libnotify_installed?
|
18
|
+
Libnotify.show :body => message, :summary => title, :icon_path => image_path(image)
|
19
|
+
end
|
23
20
|
end
|
24
21
|
end
|
25
22
|
end
|
@@ -41,5 +38,25 @@ module Guard
|
|
41
38
|
end
|
42
39
|
end
|
43
40
|
|
41
|
+
def self.growl_installed?
|
42
|
+
@installed ||= begin
|
43
|
+
require 'growl'
|
44
|
+
true
|
45
|
+
rescue LoadError
|
46
|
+
UI.info "Please install growl gem for Mac OS X notification support"
|
47
|
+
false
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.libnotify_installed?
|
52
|
+
@installed ||= begin
|
53
|
+
require 'libnotify'
|
54
|
+
true
|
55
|
+
rescue LoadError
|
56
|
+
UI.info "Please install libnotify gem for Linux notification support"
|
57
|
+
false
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
44
61
|
end
|
45
62
|
end
|
data/lib/guard/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
9
|
- 0
|
10
|
-
|
11
|
-
- 1
|
12
|
-
version: 0.2.0.beta.1
|
10
|
+
version: 0.2.0
|
13
11
|
platform: ruby
|
14
12
|
authors:
|
15
13
|
- Thibaud Guillaume-Gentil
|
@@ -17,43 +15,43 @@ autorequire:
|
|
17
15
|
bindir: bin
|
18
16
|
cert_chain: []
|
19
17
|
|
20
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-21 00:00:00 +02:00
|
21
19
|
default_executable:
|
22
20
|
dependencies:
|
23
21
|
- !ruby/object:Gem::Dependency
|
24
|
-
name:
|
22
|
+
name: bundler
|
25
23
|
prerelease: false
|
26
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
27
25
|
none: false
|
28
26
|
requirements:
|
29
27
|
- - ~>
|
30
28
|
- !ruby/object:Gem::Version
|
31
|
-
hash:
|
29
|
+
hash: 17
|
32
30
|
segments:
|
33
|
-
-
|
34
|
-
- 0
|
31
|
+
- 1
|
35
32
|
- 0
|
36
|
-
|
33
|
+
- 3
|
34
|
+
version: 1.0.3
|
37
35
|
type: :development
|
38
36
|
version_requirements: *id001
|
39
37
|
- !ruby/object:Gem::Dependency
|
40
|
-
name:
|
38
|
+
name: rspec
|
41
39
|
prerelease: false
|
42
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
43
41
|
none: false
|
44
42
|
requirements:
|
45
43
|
- - ~>
|
46
44
|
- !ruby/object:Gem::Version
|
47
|
-
hash:
|
45
|
+
hash: 13
|
48
46
|
segments:
|
47
|
+
- 2
|
49
48
|
- 0
|
50
49
|
- 1
|
51
|
-
|
52
|
-
version: 0.1.3
|
50
|
+
version: 2.0.1
|
53
51
|
type: :development
|
54
52
|
version_requirements: *id002
|
55
53
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
54
|
+
name: guard-rspec
|
57
55
|
prerelease: false
|
58
56
|
requirement: &id003 !ruby/object:Gem::Requirement
|
59
57
|
none: false
|
@@ -62,11 +60,11 @@ dependencies:
|
|
62
60
|
- !ruby/object:Gem::Version
|
63
61
|
hash: 19
|
64
62
|
segments:
|
65
|
-
- 1
|
66
63
|
- 0
|
67
|
-
-
|
68
|
-
|
69
|
-
|
64
|
+
- 1
|
65
|
+
- 4
|
66
|
+
version: 0.1.4
|
67
|
+
type: :development
|
70
68
|
version_requirements: *id003
|
71
69
|
- !ruby/object:Gem::Dependency
|
72
70
|
name: thor
|
@@ -85,37 +83,21 @@ dependencies:
|
|
85
83
|
type: :runtime
|
86
84
|
version_requirements: *id004
|
87
85
|
- !ruby/object:Gem::Dependency
|
88
|
-
name:
|
86
|
+
name: open_gem
|
89
87
|
prerelease: false
|
90
88
|
requirement: &id005 !ruby/object:Gem::Requirement
|
91
89
|
none: false
|
92
90
|
requirements:
|
93
91
|
- - ~>
|
94
92
|
- !ruby/object:Gem::Version
|
95
|
-
hash:
|
93
|
+
hash: 3
|
96
94
|
segments:
|
97
95
|
- 1
|
98
|
-
-
|
99
|
-
-
|
100
|
-
version: 1.
|
96
|
+
- 4
|
97
|
+
- 2
|
98
|
+
version: 1.4.2
|
101
99
|
type: :runtime
|
102
100
|
version_requirements: *id005
|
103
|
-
- !ruby/object:Gem::Dependency
|
104
|
-
name: libnotify
|
105
|
-
prerelease: false
|
106
|
-
requirement: &id006 !ruby/object:Gem::Requirement
|
107
|
-
none: false
|
108
|
-
requirements:
|
109
|
-
- - ~>
|
110
|
-
- !ruby/object:Gem::Version
|
111
|
-
hash: 29
|
112
|
-
segments:
|
113
|
-
- 0
|
114
|
-
- 1
|
115
|
-
- 3
|
116
|
-
version: 0.1.3
|
117
|
-
type: :runtime
|
118
|
-
version_requirements: *id006
|
119
101
|
description: Guard is a command line tool to easily handle events on files modifications.
|
120
102
|
email:
|
121
103
|
- thibaud@thibaud.me
|