guard 0.7.0.rc1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +281 -279
- data/LICENSE +19 -19
- data/README.md +487 -487
- data/bin/guard +5 -5
- data/lib/guard.rb +186 -186
- data/lib/guard/cli.rb +90 -90
- data/lib/guard/dsl.rb +148 -148
- data/lib/guard/dsl_describer.rb +28 -28
- data/lib/guard/guard.rb +58 -58
- data/lib/guard/hook.rb +72 -72
- data/lib/guard/interactor.rb +40 -40
- data/lib/guard/listener.rb +191 -191
- data/lib/guard/listeners/darwin.rb +47 -47
- data/lib/guard/listeners/linux.rb +74 -74
- data/lib/guard/listeners/polling.rb +37 -37
- data/lib/guard/listeners/windows.rb +42 -42
- data/lib/guard/notifier.rb +136 -136
- data/lib/guard/templates/Guardfile +2 -2
- data/lib/guard/ui.rb +110 -110
- data/lib/guard/version.rb +3 -3
- data/lib/guard/watcher.rb +66 -66
- data/man/guard.1 +93 -93
- data/man/guard.1.html +176 -176
- metadata +11 -25
- data/lib/guard.rbc +0 -3978
- data/lib/guard/dsl.rbc +0 -3248
- data/lib/guard/dsl_describer.rbc +0 -785
- data/lib/guard/guard.rbc +0 -1007
- data/lib/guard/interactor.rbc +0 -1218
- data/lib/guard/listener.rbc +0 -3507
- data/lib/guard/listeners/darwin.rbc +0 -1106
- data/lib/guard/listeners/linux.rbc +0 -1747
- data/lib/guard/listeners/polling.rbc +0 -775
- data/lib/guard/listeners/windows.rbc +0 -967
- data/lib/guard/notifier.rbc +0 -2994
- data/lib/guard/ui.rbc +0 -2416
- data/lib/guard/version.rbc +0 -180
- data/lib/guard/watcher.rbc +0 -1854
data/lib/guard/dsl.rb
CHANGED
@@ -1,148 +1,148 @@
|
|
1
|
-
module Guard
|
2
|
-
class Dsl
|
3
|
-
class << self
|
4
|
-
@@options = nil
|
5
|
-
|
6
|
-
def evaluate_guardfile(options = {})
|
7
|
-
options.is_a?(Hash) or raise ArgumentError.new("evaluate_guardfile not passed a Hash!")
|
8
|
-
|
9
|
-
@@options = options.dup
|
10
|
-
fetch_guardfile_contents
|
11
|
-
instance_eval_guardfile(guardfile_contents_with_user_config)
|
12
|
-
|
13
|
-
UI.error "No guards found in Guardfile, please add at least one." if !::Guard.guards.nil? && ::Guard.guards.empty?
|
14
|
-
end
|
15
|
-
|
16
|
-
def reevaluate_guardfile
|
17
|
-
::Guard.guards.clear
|
18
|
-
@@options.delete(:guardfile_contents)
|
19
|
-
Dsl.evaluate_guardfile(@@options)
|
20
|
-
msg = "Guardfile has been re-evaluated."
|
21
|
-
UI.info(msg)
|
22
|
-
Notifier.notify(msg)
|
23
|
-
end
|
24
|
-
|
25
|
-
def instance_eval_guardfile(contents)
|
26
|
-
begin
|
27
|
-
new.instance_eval(contents, @@options[:guardfile_path], 1)
|
28
|
-
rescue
|
29
|
-
UI.error "Invalid Guardfile, original error is:\n#{$!}"
|
30
|
-
exit 1
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def guardfile_include?(guard_name)
|
35
|
-
guardfile_contents.match(/^guard\s*\(?\s*['":]#{guard_name}['"]?/)
|
36
|
-
end
|
37
|
-
|
38
|
-
def read_guardfile(guardfile_path)
|
39
|
-
begin
|
40
|
-
@@options[:guardfile_path] = guardfile_path
|
41
|
-
@@options[:guardfile_contents] = File.read(guardfile_path)
|
42
|
-
rescue
|
43
|
-
UI.error("Error reading file #{guardfile_path}")
|
44
|
-
exit 1
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def fetch_guardfile_contents
|
49
|
-
# TODO: do we need .rc file interaction?
|
50
|
-
if @@options[:guardfile_contents]
|
51
|
-
UI.info "Using inline Guardfile."
|
52
|
-
@@options[:guardfile_path] = 'Inline Guardfile'
|
53
|
-
|
54
|
-
elsif @@options[:guardfile]
|
55
|
-
if File.exist?(@@options[:guardfile])
|
56
|
-
read_guardfile(@@options[:guardfile])
|
57
|
-
UI.info "Using Guardfile at #{@@options[:guardfile]}."
|
58
|
-
else
|
59
|
-
UI.error "No Guardfile exists at #{@@options[:guardfile]}."
|
60
|
-
exit 1
|
61
|
-
end
|
62
|
-
|
63
|
-
else
|
64
|
-
if File.exist?(guardfile_default_path)
|
65
|
-
read_guardfile(guardfile_default_path)
|
66
|
-
else
|
67
|
-
UI.error "No Guardfile found, please create one with `guard init`."
|
68
|
-
exit 1
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
unless guardfile_contents_usable?
|
73
|
-
UI.error "The command file(#{@@options[:guardfile]}) seems to be empty."
|
74
|
-
exit 1
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def guardfile_contents
|
79
|
-
@@options ? @@options[:guardfile_contents] : ""
|
80
|
-
end
|
81
|
-
|
82
|
-
def guardfile_contents_with_user_config
|
83
|
-
config = File.read(user_config_path) if File.exist?(user_config_path)
|
84
|
-
[guardfile_contents, config].join("\n")
|
85
|
-
end
|
86
|
-
|
87
|
-
def guardfile_path
|
88
|
-
@@options ? @@options[:guardfile_path] : ""
|
89
|
-
end
|
90
|
-
|
91
|
-
def guardfile_contents_usable?
|
92
|
-
guardfile_contents && guardfile_contents.size >= 'guard :a'.size # smallest guard-definition
|
93
|
-
end
|
94
|
-
|
95
|
-
def guardfile_default_path
|
96
|
-
File.exist?(local_guardfile_path) ? local_guardfile_path : home_guardfile_path
|
97
|
-
end
|
98
|
-
|
99
|
-
private
|
100
|
-
|
101
|
-
def local_guardfile_path
|
102
|
-
File.join(Dir.pwd, "Guardfile")
|
103
|
-
end
|
104
|
-
|
105
|
-
def home_guardfile_path
|
106
|
-
File.expand_path(File.join("~", ".Guardfile"))
|
107
|
-
end
|
108
|
-
|
109
|
-
def user_config_path
|
110
|
-
File.expand_path(File.join("~", ".guard.rb"))
|
111
|
-
end
|
112
|
-
|
113
|
-
end
|
114
|
-
|
115
|
-
def group(name, &guard_definition)
|
116
|
-
@groups = @@options[:group] || []
|
117
|
-
name = name.to_sym
|
118
|
-
|
119
|
-
if guard_definition && (@groups.empty? || @groups.map(&:to_sym).include?(name))
|
120
|
-
@current_group = name
|
121
|
-
guard_definition.call
|
122
|
-
@current_group = nil
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
def guard(name, options = {}, &watch_and_callback_definition)
|
127
|
-
@watchers = []
|
128
|
-
@callbacks = []
|
129
|
-
watch_and_callback_definition.call if watch_and_callback_definition
|
130
|
-
options.update(:group => (@current_group || :default))
|
131
|
-
::Guard.add_guard(name.to_s.downcase.to_sym, @watchers, @callbacks, options)
|
132
|
-
end
|
133
|
-
|
134
|
-
def watch(pattern, &action)
|
135
|
-
@watchers << ::Guard::Watcher.new(pattern, action)
|
136
|
-
end
|
137
|
-
|
138
|
-
def callback(*args, &listener)
|
139
|
-
listener, events = args.size > 1 ? args : [listener, args[0]]
|
140
|
-
@callbacks << { :events => events, :listener => listener }
|
141
|
-
end
|
142
|
-
|
143
|
-
def ignore_paths(*paths)
|
144
|
-
UI.info "Ignoring paths: #{paths.join(', ')}"
|
145
|
-
::Guard.listener.ignore_paths.push(*paths)
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
1
|
+
module Guard
|
2
|
+
class Dsl
|
3
|
+
class << self
|
4
|
+
@@options = nil
|
5
|
+
|
6
|
+
def evaluate_guardfile(options = {})
|
7
|
+
options.is_a?(Hash) or raise ArgumentError.new("evaluate_guardfile not passed a Hash!")
|
8
|
+
|
9
|
+
@@options = options.dup
|
10
|
+
fetch_guardfile_contents
|
11
|
+
instance_eval_guardfile(guardfile_contents_with_user_config)
|
12
|
+
|
13
|
+
UI.error "No guards found in Guardfile, please add at least one." if !::Guard.guards.nil? && ::Guard.guards.empty?
|
14
|
+
end
|
15
|
+
|
16
|
+
def reevaluate_guardfile
|
17
|
+
::Guard.guards.clear
|
18
|
+
@@options.delete(:guardfile_contents)
|
19
|
+
Dsl.evaluate_guardfile(@@options)
|
20
|
+
msg = "Guardfile has been re-evaluated."
|
21
|
+
UI.info(msg)
|
22
|
+
Notifier.notify(msg)
|
23
|
+
end
|
24
|
+
|
25
|
+
def instance_eval_guardfile(contents)
|
26
|
+
begin
|
27
|
+
new.instance_eval(contents, @@options[:guardfile_path], 1)
|
28
|
+
rescue
|
29
|
+
UI.error "Invalid Guardfile, original error is:\n#{$!}"
|
30
|
+
exit 1
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def guardfile_include?(guard_name)
|
35
|
+
guardfile_contents.match(/^guard\s*\(?\s*['":]#{guard_name}['"]?/)
|
36
|
+
end
|
37
|
+
|
38
|
+
def read_guardfile(guardfile_path)
|
39
|
+
begin
|
40
|
+
@@options[:guardfile_path] = guardfile_path
|
41
|
+
@@options[:guardfile_contents] = File.read(guardfile_path)
|
42
|
+
rescue
|
43
|
+
UI.error("Error reading file #{guardfile_path}")
|
44
|
+
exit 1
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def fetch_guardfile_contents
|
49
|
+
# TODO: do we need .rc file interaction?
|
50
|
+
if @@options[:guardfile_contents]
|
51
|
+
UI.info "Using inline Guardfile."
|
52
|
+
@@options[:guardfile_path] = 'Inline Guardfile'
|
53
|
+
|
54
|
+
elsif @@options[:guardfile]
|
55
|
+
if File.exist?(@@options[:guardfile])
|
56
|
+
read_guardfile(@@options[:guardfile])
|
57
|
+
UI.info "Using Guardfile at #{@@options[:guardfile]}."
|
58
|
+
else
|
59
|
+
UI.error "No Guardfile exists at #{@@options[:guardfile]}."
|
60
|
+
exit 1
|
61
|
+
end
|
62
|
+
|
63
|
+
else
|
64
|
+
if File.exist?(guardfile_default_path)
|
65
|
+
read_guardfile(guardfile_default_path)
|
66
|
+
else
|
67
|
+
UI.error "No Guardfile found, please create one with `guard init`."
|
68
|
+
exit 1
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
unless guardfile_contents_usable?
|
73
|
+
UI.error "The command file(#{@@options[:guardfile]}) seems to be empty."
|
74
|
+
exit 1
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def guardfile_contents
|
79
|
+
@@options ? @@options[:guardfile_contents] : ""
|
80
|
+
end
|
81
|
+
|
82
|
+
def guardfile_contents_with_user_config
|
83
|
+
config = File.read(user_config_path) if File.exist?(user_config_path)
|
84
|
+
[guardfile_contents, config].join("\n")
|
85
|
+
end
|
86
|
+
|
87
|
+
def guardfile_path
|
88
|
+
@@options ? @@options[:guardfile_path] : ""
|
89
|
+
end
|
90
|
+
|
91
|
+
def guardfile_contents_usable?
|
92
|
+
guardfile_contents && guardfile_contents.size >= 'guard :a'.size # smallest guard-definition
|
93
|
+
end
|
94
|
+
|
95
|
+
def guardfile_default_path
|
96
|
+
File.exist?(local_guardfile_path) ? local_guardfile_path : home_guardfile_path
|
97
|
+
end
|
98
|
+
|
99
|
+
private
|
100
|
+
|
101
|
+
def local_guardfile_path
|
102
|
+
File.join(Dir.pwd, "Guardfile")
|
103
|
+
end
|
104
|
+
|
105
|
+
def home_guardfile_path
|
106
|
+
File.expand_path(File.join("~", ".Guardfile"))
|
107
|
+
end
|
108
|
+
|
109
|
+
def user_config_path
|
110
|
+
File.expand_path(File.join("~", ".guard.rb"))
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
def group(name, &guard_definition)
|
116
|
+
@groups = @@options[:group] || []
|
117
|
+
name = name.to_sym
|
118
|
+
|
119
|
+
if guard_definition && (@groups.empty? || @groups.map(&:to_sym).include?(name))
|
120
|
+
@current_group = name
|
121
|
+
guard_definition.call
|
122
|
+
@current_group = nil
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def guard(name, options = {}, &watch_and_callback_definition)
|
127
|
+
@watchers = []
|
128
|
+
@callbacks = []
|
129
|
+
watch_and_callback_definition.call if watch_and_callback_definition
|
130
|
+
options.update(:group => (@current_group || :default))
|
131
|
+
::Guard.add_guard(name.to_s.downcase.to_sym, @watchers, @callbacks, options)
|
132
|
+
end
|
133
|
+
|
134
|
+
def watch(pattern, &action)
|
135
|
+
@watchers << ::Guard::Watcher.new(pattern, action)
|
136
|
+
end
|
137
|
+
|
138
|
+
def callback(*args, &listener)
|
139
|
+
listener, events = args.size > 1 ? args : [listener, args[0]]
|
140
|
+
@callbacks << { :events => events, :listener => listener }
|
141
|
+
end
|
142
|
+
|
143
|
+
def ignore_paths(*paths)
|
144
|
+
UI.info "Ignoring paths: #{paths.join(', ')}"
|
145
|
+
::Guard.listener.ignore_paths.push(*paths)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
data/lib/guard/dsl_describer.rb
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
require 'guard/dsl'
|
2
|
-
|
3
|
-
module Guard
|
4
|
-
class DslDescriber < Dsl
|
5
|
-
@@guardfile_structure = [ { :guards => [] } ]
|
6
|
-
|
7
|
-
class << self
|
8
|
-
def guardfile_structure
|
9
|
-
@@guardfile_structure
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
def group(name, &guard_definition)
|
15
|
-
@@guardfile_structure << { :group => name.to_sym, :guards => [] }
|
16
|
-
|
17
|
-
@group = true
|
18
|
-
guard_definition.call
|
19
|
-
@group = false
|
20
|
-
end
|
21
|
-
|
22
|
-
def guard(name, options = {}, &watch_definition)
|
23
|
-
node = (@group ? @@guardfile_structure.last : @@guardfile_structure.first)
|
24
|
-
|
25
|
-
node[:guards] << { :name => name, :options => options }
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
1
|
+
require 'guard/dsl'
|
2
|
+
|
3
|
+
module Guard
|
4
|
+
class DslDescriber < Dsl
|
5
|
+
@@guardfile_structure = [ { :guards => [] } ]
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def guardfile_structure
|
9
|
+
@@guardfile_structure
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def group(name, &guard_definition)
|
15
|
+
@@guardfile_structure << { :group => name.to_sym, :guards => [] }
|
16
|
+
|
17
|
+
@group = true
|
18
|
+
guard_definition.call
|
19
|
+
@group = false
|
20
|
+
end
|
21
|
+
|
22
|
+
def guard(name, options = {}, &watch_definition)
|
23
|
+
node = (@group ? @@guardfile_structure.last : @@guardfile_structure.first)
|
24
|
+
|
25
|
+
node[:guards] << { :name => name, :options => options }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/guard/guard.rb
CHANGED
@@ -1,58 +1,58 @@
|
|
1
|
-
module Guard
|
2
|
-
class Guard
|
3
|
-
include Hook
|
4
|
-
|
5
|
-
attr_accessor :watchers, :options, :group
|
6
|
-
|
7
|
-
def initialize(watchers = [], options = {})
|
8
|
-
@group = options.delete(:group) || :default
|
9
|
-
@watchers, @options = watchers, options
|
10
|
-
end
|
11
|
-
|
12
|
-
# Guardfile template needed inside guard gem
|
13
|
-
def self.init(name)
|
14
|
-
if ::Guard::Dsl.guardfile_include?(name)
|
15
|
-
::Guard::UI.info "Guardfile already includes #{name} guard"
|
16
|
-
else
|
17
|
-
content = File.read('Guardfile')
|
18
|
-
guard = File.read("#{::Guard.locate_guard(name)}/lib/guard/#{name}/templates/Guardfile")
|
19
|
-
File.open('Guardfile', 'wb') do |f|
|
20
|
-
f.puts(content)
|
21
|
-
f.puts("")
|
22
|
-
f.puts(guard)
|
23
|
-
end
|
24
|
-
::Guard::UI.info "#{name} guard added to Guardfile, feel free to edit it"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
# ================
|
29
|
-
# = Guard method =
|
30
|
-
# ================
|
31
|
-
|
32
|
-
# Call once when guard starts
|
33
|
-
# Please override initialize method to init stuff
|
34
|
-
def start
|
35
|
-
true
|
36
|
-
end
|
37
|
-
|
38
|
-
# Call once when guard quit
|
39
|
-
def stop
|
40
|
-
true
|
41
|
-
end
|
42
|
-
|
43
|
-
# Should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/...
|
44
|
-
def reload
|
45
|
-
true
|
46
|
-
end
|
47
|
-
|
48
|
-
# Should be principally used for long action like running all specs/tests/...
|
49
|
-
def run_all
|
50
|
-
true
|
51
|
-
end
|
52
|
-
|
53
|
-
def run_on_change(paths)
|
54
|
-
true
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
end
|
1
|
+
module Guard
|
2
|
+
class Guard
|
3
|
+
include Hook
|
4
|
+
|
5
|
+
attr_accessor :watchers, :options, :group
|
6
|
+
|
7
|
+
def initialize(watchers = [], options = {})
|
8
|
+
@group = options.delete(:group) || :default
|
9
|
+
@watchers, @options = watchers, options
|
10
|
+
end
|
11
|
+
|
12
|
+
# Guardfile template needed inside guard gem
|
13
|
+
def self.init(name)
|
14
|
+
if ::Guard::Dsl.guardfile_include?(name)
|
15
|
+
::Guard::UI.info "Guardfile already includes #{name} guard"
|
16
|
+
else
|
17
|
+
content = File.read('Guardfile')
|
18
|
+
guard = File.read("#{::Guard.locate_guard(name)}/lib/guard/#{name}/templates/Guardfile")
|
19
|
+
File.open('Guardfile', 'wb') do |f|
|
20
|
+
f.puts(content)
|
21
|
+
f.puts("")
|
22
|
+
f.puts(guard)
|
23
|
+
end
|
24
|
+
::Guard::UI.info "#{name} guard added to Guardfile, feel free to edit it"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# ================
|
29
|
+
# = Guard method =
|
30
|
+
# ================
|
31
|
+
|
32
|
+
# Call once when guard starts
|
33
|
+
# Please override initialize method to init stuff
|
34
|
+
def start
|
35
|
+
true
|
36
|
+
end
|
37
|
+
|
38
|
+
# Call once when guard quit
|
39
|
+
def stop
|
40
|
+
true
|
41
|
+
end
|
42
|
+
|
43
|
+
# Should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/...
|
44
|
+
def reload
|
45
|
+
true
|
46
|
+
end
|
47
|
+
|
48
|
+
# Should be principally used for long action like running all specs/tests/...
|
49
|
+
def run_all
|
50
|
+
true
|
51
|
+
end
|
52
|
+
|
53
|
+
def run_on_change(paths)
|
54
|
+
true
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|