guard 0.1.0.beta.1 → 0.1.0.beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/guard.rb +30 -13
- data/lib/guard/cli.rb +17 -0
- data/lib/guard/dsl.rb +7 -3
- data/lib/guard/guard.rb +16 -0
- data/lib/guard/listener.rb +2 -0
- data/lib/guard/templates/Guardfile +2 -0
- data/lib/guard/ui.rb +1 -1
- data/lib/guard/version.rb +1 -1
- data/lib/guard/watcher.rb +3 -4
- metadata +53 -33
data/lib/guard.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
|
1
3
|
module Guard
|
2
4
|
|
3
5
|
autoload :UI, 'guard/ui'
|
@@ -16,26 +18,42 @@ module Guard
|
|
16
18
|
@guards = []
|
17
19
|
|
18
20
|
Dsl.evaluate_guardfile
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
if guards.empty?
|
22
|
+
UI.error "No guards found in Guardfile, too bad."
|
23
|
+
else
|
24
|
+
Interactor.init_signal_traps
|
25
|
+
|
26
|
+
listener.on_change do |files|
|
27
|
+
run do
|
28
|
+
guards.each do |guard|
|
29
|
+
paths = Watcher.match_files(guard, files)
|
30
|
+
guard.run_on_change(paths) unless paths.empty?
|
31
|
+
end
|
26
32
|
end
|
27
33
|
end
|
34
|
+
|
35
|
+
UI.info "Guard is now watching at '#{Dir.pwd}'"
|
36
|
+
guards.each(&:start)
|
37
|
+
listener.start
|
28
38
|
end
|
29
|
-
|
30
|
-
UI.info "Guard is now watching at '#{Dir.pwd}'"
|
31
|
-
guards.each(&:start)
|
32
|
-
listener.start
|
33
39
|
end
|
34
40
|
|
35
41
|
def add_guard(name, watchers = [], options = {})
|
42
|
+
guard_class = get_guard_class(name)
|
43
|
+
@guards << guard_class.new(watchers, options)
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_guard_class(name)
|
36
47
|
require "guard/#{name.downcase}"
|
37
48
|
guard_class = ObjectSpace.each_object(Class).detect { |c| c.to_s.downcase.match "^guard::#{name.downcase}" }
|
38
|
-
|
49
|
+
rescue LoadError
|
50
|
+
UI.error "#{name} guard gem not found, try to add it to your Gemfile."
|
51
|
+
end
|
52
|
+
|
53
|
+
def locate_guard(name)
|
54
|
+
spec = Bundler.load.specs.find{|s| s.name == "guard-#{name}" }
|
55
|
+
UI.error "Could not find gem '#{name}' in the current Gemfile." unless spec
|
56
|
+
spec.full_gem_path
|
39
57
|
end
|
40
58
|
|
41
59
|
def run
|
@@ -45,5 +63,4 @@ module Guard
|
|
45
63
|
end
|
46
64
|
|
47
65
|
end
|
48
|
-
|
49
66
|
end
|
data/lib/guard/cli.rb
CHANGED
@@ -16,5 +16,22 @@ module Guard
|
|
16
16
|
Guard::UI.info "Guard version #{Guard::VERSION}"
|
17
17
|
end
|
18
18
|
map %w(-v --version) => :version
|
19
|
+
|
20
|
+
desc "init [GUARD]", "Generates a Guardfile into the current working directory, or add it given guard"
|
21
|
+
def init(guard_name = nil)
|
22
|
+
if !File.exist?("Guardfile")
|
23
|
+
puts "Writing new Guardfile to #{Dir.pwd}/Guardfile"
|
24
|
+
FileUtils.cp(File.expand_path('../templates/Guardfile', __FILE__), 'Guardfile')
|
25
|
+
elsif guard_name.nil?
|
26
|
+
Guard::UI.error "Guardfile already exists at #{Dir.pwd}/Guardfile"
|
27
|
+
exit 1
|
28
|
+
end
|
29
|
+
|
30
|
+
if guard_name
|
31
|
+
guard_class = Guard.get_guard_class(guard_name)
|
32
|
+
guard_class.init(guard_name)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
19
36
|
end
|
20
37
|
end
|
data/lib/guard/dsl.rb
CHANGED
@@ -10,14 +10,18 @@ module Guard
|
|
10
10
|
exit 1
|
11
11
|
end
|
12
12
|
|
13
|
+
def self.guardfile_included?(guard_name)
|
14
|
+
File.read('Guardfile').include?("guard '#{guard_name}'")
|
15
|
+
end
|
16
|
+
|
13
17
|
def guard(name, options = {}, &definition)
|
14
18
|
@watchers = []
|
15
|
-
definition.call
|
16
|
-
Guard.add_guard(name, @watchers, options)
|
19
|
+
definition.call if definition
|
20
|
+
::Guard.add_guard(name, @watchers, options)
|
17
21
|
end
|
18
22
|
|
19
23
|
def watch(pattern, &action)
|
20
|
-
@watchers << Guard::Watcher.new(pattern, action)
|
24
|
+
@watchers << ::Guard::Watcher.new(pattern, action)
|
21
25
|
end
|
22
26
|
|
23
27
|
end
|
data/lib/guard/guard.rb
CHANGED
@@ -6,6 +6,22 @@ module Guard
|
|
6
6
|
@watchers, @options = watchers, options
|
7
7
|
end
|
8
8
|
|
9
|
+
# Guardfile template needed inside guard gem
|
10
|
+
def self.init(name)
|
11
|
+
if ::Guard::Dsl.guardfile_included?(name)
|
12
|
+
::Guard::UI.info "Guardfile already include #{name} guard"
|
13
|
+
else
|
14
|
+
content = File.read('Guardfile')
|
15
|
+
guard = File.read("#{::Guard.locate_guard(name)}/lib/guard/#{name}/templates/Guardfile")
|
16
|
+
File.open('Guardfile', 'wb') do |f|
|
17
|
+
f.puts content
|
18
|
+
f.puts ""
|
19
|
+
f.puts guard
|
20
|
+
end
|
21
|
+
::Guard::UI.info "#{name} guard added to Guardfile, feel free to edit it"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
9
25
|
# ================
|
10
26
|
# = Guard method =
|
11
27
|
# ================
|
data/lib/guard/listener.rb
CHANGED
data/lib/guard/ui.rb
CHANGED
@@ -5,7 +5,7 @@ module Guard
|
|
5
5
|
def info(message, options = {})
|
6
6
|
unless ENV["GUARD_ENV"] == "test"
|
7
7
|
reset_line if options[:reset]
|
8
|
-
clear if options.key?(:clear) ? options[:clear] : ::Guard.options[:clear]
|
8
|
+
clear if options.key?(:clear) ? options[:clear] : (::Guard.options && ::Guard.options[:clear])
|
9
9
|
puts reset_color(message) if message != ''
|
10
10
|
end
|
11
11
|
end
|
data/lib/guard/version.rb
CHANGED
data/lib/guard/watcher.rb
CHANGED
@@ -12,11 +12,10 @@ module Guard
|
|
12
12
|
if matches = file.match(watcher.pattern)
|
13
13
|
if watcher.action
|
14
14
|
begin
|
15
|
-
|
16
|
-
when -1
|
17
|
-
result = watcher.action.call
|
18
|
-
when 1
|
15
|
+
if watcher.action.arity == 1
|
19
16
|
result = watcher.action.call(matches)
|
17
|
+
else
|
18
|
+
result = watcher.action.call
|
20
19
|
end
|
21
20
|
rescue
|
22
21
|
UI.info "Problem with watch action"
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 62196407
|
5
5
|
prerelease: true
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
9
|
- 0
|
10
10
|
- beta
|
11
|
-
-
|
12
|
-
version: 0.1.0.beta.
|
11
|
+
- 2
|
12
|
+
version: 0.1.0.beta.2
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- Thibaud Guillaume-Gentil
|
@@ -17,63 +17,80 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2010-10-
|
20
|
+
date: 2010-10-07 00:00:00 +02:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
24
|
-
name:
|
24
|
+
name: rspec
|
25
25
|
prerelease: false
|
26
26
|
requirement: &id001 !ruby/object:Gem::Requirement
|
27
27
|
none: false
|
28
28
|
requirements:
|
29
29
|
- - ~>
|
30
30
|
- !ruby/object:Gem::Version
|
31
|
-
hash:
|
31
|
+
hash: 7712058
|
32
32
|
segments:
|
33
|
-
-
|
33
|
+
- 2
|
34
34
|
- 0
|
35
|
-
-
|
36
|
-
|
35
|
+
- 0
|
36
|
+
- rc
|
37
|
+
version: 2.0.0.rc
|
37
38
|
type: :development
|
38
39
|
version_requirements: *id001
|
39
40
|
- !ruby/object:Gem::Dependency
|
40
|
-
name: rspec
|
41
|
+
name: guard-rspec
|
41
42
|
prerelease: false
|
42
43
|
requirement: &id002 !ruby/object:Gem::Requirement
|
43
44
|
none: false
|
44
45
|
requirements:
|
45
46
|
- - ~>
|
46
47
|
- !ruby/object:Gem::Version
|
47
|
-
hash:
|
48
|
+
hash: 62196407
|
48
49
|
segments:
|
49
|
-
- 2
|
50
50
|
- 0
|
51
|
+
- 1
|
51
52
|
- 0
|
52
53
|
- beta
|
53
|
-
-
|
54
|
-
version:
|
54
|
+
- 2
|
55
|
+
version: 0.1.0.beta.2
|
55
56
|
type: :development
|
56
57
|
version_requirements: *id002
|
57
58
|
- !ruby/object:Gem::Dependency
|
58
|
-
name:
|
59
|
+
name: bundler
|
59
60
|
prerelease: false
|
60
61
|
requirement: &id003 !ruby/object:Gem::Requirement
|
61
62
|
none: false
|
62
63
|
requirements:
|
63
64
|
- - ~>
|
64
65
|
- !ruby/object:Gem::Version
|
65
|
-
hash:
|
66
|
+
hash: 19
|
66
67
|
segments:
|
68
|
+
- 1
|
67
69
|
- 0
|
68
|
-
- 14
|
69
70
|
- 2
|
70
|
-
version: 0.
|
71
|
+
version: 1.0.2
|
71
72
|
type: :runtime
|
72
73
|
version_requirements: *id003
|
73
74
|
- !ruby/object:Gem::Dependency
|
74
|
-
name:
|
75
|
+
name: thor
|
75
76
|
prerelease: false
|
76
77
|
requirement: &id004 !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
hash: 33
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
- 14
|
86
|
+
- 3
|
87
|
+
version: 0.14.3
|
88
|
+
type: :runtime
|
89
|
+
version_requirements: *id004
|
90
|
+
- !ruby/object:Gem::Dependency
|
91
|
+
name: sys-uname
|
92
|
+
prerelease: false
|
93
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
77
94
|
none: false
|
78
95
|
requirements:
|
79
96
|
- - ~>
|
@@ -85,11 +102,11 @@ dependencies:
|
|
85
102
|
- 4
|
86
103
|
version: 0.8.4
|
87
104
|
type: :runtime
|
88
|
-
version_requirements: *
|
105
|
+
version_requirements: *id005
|
89
106
|
- !ruby/object:Gem::Dependency
|
90
107
|
name: growl
|
91
108
|
prerelease: false
|
92
|
-
requirement: &
|
109
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
93
110
|
none: false
|
94
111
|
requirements:
|
95
112
|
- - ~>
|
@@ -101,25 +118,27 @@ dependencies:
|
|
101
118
|
- 3
|
102
119
|
version: 1.0.3
|
103
120
|
type: :runtime
|
104
|
-
version_requirements: *
|
121
|
+
version_requirements: *id006
|
105
122
|
- !ruby/object:Gem::Dependency
|
106
123
|
name: rb-inotify
|
107
124
|
prerelease: false
|
108
|
-
requirement: &
|
125
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
109
126
|
none: false
|
110
127
|
requirements:
|
111
|
-
- -
|
128
|
+
- - ~>
|
112
129
|
- !ruby/object:Gem::Version
|
113
|
-
hash:
|
130
|
+
hash: 61
|
114
131
|
segments:
|
115
132
|
- 0
|
116
|
-
|
133
|
+
- 8
|
134
|
+
- 1
|
135
|
+
version: 0.8.1
|
117
136
|
type: :runtime
|
118
|
-
version_requirements: *
|
137
|
+
version_requirements: *id007
|
119
138
|
- !ruby/object:Gem::Dependency
|
120
139
|
name: libnotify
|
121
140
|
prerelease: false
|
122
|
-
requirement: &
|
141
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
123
142
|
none: false
|
124
143
|
requirements:
|
125
144
|
- - ~>
|
@@ -131,7 +150,7 @@ dependencies:
|
|
131
150
|
- 3
|
132
151
|
version: 0.1.3
|
133
152
|
type: :runtime
|
134
|
-
version_requirements: *
|
153
|
+
version_requirements: *id008
|
135
154
|
description: Guard is a command line tool to easly manage script launch when your files change
|
136
155
|
email:
|
137
156
|
- thibaud@thibaud.me
|
@@ -153,6 +172,7 @@ files:
|
|
153
172
|
- lib/guard/interactor.rb
|
154
173
|
- lib/guard/listener.rb
|
155
174
|
- lib/guard/notifier.rb
|
175
|
+
- lib/guard/templates/Guardfile
|
156
176
|
- lib/guard/ui.rb
|
157
177
|
- lib/guard/version.rb
|
158
178
|
- lib/guard/watcher.rb
|
@@ -182,14 +202,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
182
202
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
183
203
|
none: false
|
184
204
|
requirements:
|
185
|
-
- - "
|
205
|
+
- - ">="
|
186
206
|
- !ruby/object:Gem::Version
|
187
|
-
hash:
|
207
|
+
hash: 23
|
188
208
|
segments:
|
189
209
|
- 1
|
190
210
|
- 3
|
191
|
-
-
|
192
|
-
version: 1.3.
|
211
|
+
- 6
|
212
|
+
version: 1.3.6
|
193
213
|
requirements: []
|
194
214
|
|
195
215
|
rubyforge_project: guard
|