guard 1.8.3 → 2.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +68 -10
- data/README.md +54 -33
- data/lib/guard.rb +133 -483
- data/lib/guard/cli.rb +78 -82
- data/lib/guard/commander.rb +121 -0
- data/lib/guard/commands/all.rb +1 -1
- data/lib/guard/commands/reload.rb +1 -1
- data/lib/guard/deprecated_methods.rb +59 -0
- data/lib/guard/deprecator.rb +107 -0
- data/lib/guard/dsl.rb +143 -329
- data/lib/guard/dsl_describer.rb +101 -57
- data/lib/guard/group.rb +27 -8
- data/lib/guard/guard.rb +25 -150
- data/lib/guard/guardfile.rb +35 -85
- data/lib/guard/guardfile/evaluator.rb +245 -0
- data/lib/guard/guardfile/generator.rb +89 -0
- data/lib/guard/interactor.rb +147 -163
- data/lib/guard/notifier.rb +83 -137
- data/lib/guard/notifiers/base.rb +220 -0
- data/lib/guard/notifiers/emacs.rb +39 -37
- data/lib/guard/notifiers/file_notifier.rb +29 -25
- data/lib/guard/notifiers/gntp.rb +68 -75
- data/lib/guard/notifiers/growl.rb +49 -52
- data/lib/guard/notifiers/growl_notify.rb +51 -56
- data/lib/guard/notifiers/libnotify.rb +41 -48
- data/lib/guard/notifiers/notifysend.rb +58 -38
- data/lib/guard/notifiers/rb_notifu.rb +54 -54
- data/lib/guard/notifiers/terminal_notifier.rb +48 -36
- data/lib/guard/notifiers/terminal_title.rb +23 -19
- data/lib/guard/notifiers/tmux.rb +110 -93
- data/lib/guard/options.rb +21 -0
- data/lib/guard/plugin.rb +66 -0
- data/lib/guard/plugin/base.rb +178 -0
- data/lib/guard/plugin/hooker.rb +123 -0
- data/lib/guard/plugin_util.rb +158 -0
- data/lib/guard/rake_task.rb +47 -0
- data/lib/guard/runner.rb +62 -82
- data/lib/guard/setuper.rb +248 -0
- data/lib/guard/ui.rb +24 -80
- data/lib/guard/ui/colors.rb +60 -0
- data/lib/guard/version.rb +1 -2
- data/lib/guard/watcher.rb +30 -30
- data/man/guard.1 +4 -4
- data/man/guard.1.html +6 -4
- metadata +25 -11
- data/lib/guard/hook.rb +0 -120
data/lib/guard/dsl_describer.rb
CHANGED
@@ -1,86 +1,130 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
require 'formatador'
|
3
|
+
|
4
|
+
require 'guard/guardfile/evaluator'
|
5
|
+
require 'guard/ui'
|
2
6
|
|
3
7
|
module Guard
|
4
8
|
|
5
|
-
# The DslDescriber
|
6
|
-
# of
|
7
|
-
#
|
9
|
+
# The DslDescriber evaluates the Guardfile and creates an internal structure
|
10
|
+
# of it that is used in some inspection utility methods like the CLI commands
|
11
|
+
# `show` and `list`.
|
8
12
|
#
|
9
13
|
# @see Guard::Dsl
|
10
14
|
# @see Guard::CLI
|
11
15
|
#
|
12
|
-
class DslDescriber
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
class DslDescriber
|
17
|
+
|
18
|
+
attr_reader :options
|
19
|
+
|
20
|
+
# Initializes a new DslDescriber object.
|
21
|
+
#
|
22
|
+
# @option options [String] guardfile the path to a valid Guardfile
|
23
|
+
# @option options [String] guardfile_contents a string representing the content of a valid Guardfile
|
24
|
+
#
|
25
|
+
# @see Guard::Guardfile::Evaluator#initialize
|
26
|
+
#
|
27
|
+
def initialize(options = {})
|
28
|
+
@options = options
|
29
|
+
::Guard.reset_groups
|
30
|
+
::Guard.reset_plugins
|
31
|
+
end
|
20
32
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
def evaluate_guardfile(options = { })
|
29
|
-
::Guard.options = { :plugin => [], :group => [] }
|
30
|
-
::Guard.setup_groups
|
31
|
-
::Guard.setup_guards
|
33
|
+
# List the Guard plugins that are available for use in your system and marks
|
34
|
+
# those that are currently used in your `Guardfile`.
|
35
|
+
#
|
36
|
+
# @see CLI#list
|
37
|
+
#
|
38
|
+
def list
|
39
|
+
_evaluate_guardfile
|
32
40
|
|
33
|
-
|
41
|
+
rows = ::Guard::PluginUtil.plugin_names.sort.uniq.inject([]) do |rows, name|
|
42
|
+
rows << { Plugin: name.capitalize, Guardfile: ::Guard.plugins(name) ? '✔' : '✘' }
|
34
43
|
end
|
35
44
|
|
36
|
-
|
37
|
-
|
38
|
-
#
|
39
|
-
# @param [Hash] options the Guard options
|
40
|
-
#
|
41
|
-
def list(options)
|
42
|
-
evaluate_guardfile(options)
|
45
|
+
Formatador.display_compact_table(rows, [:Plugin, :Guardfile])
|
46
|
+
end
|
43
47
|
|
44
|
-
|
45
|
-
|
48
|
+
# Shows all Guard plugins and their options that are defined in
|
49
|
+
# the `Guardfile`.
|
50
|
+
#
|
51
|
+
# @see CLI#show
|
52
|
+
#
|
53
|
+
def show
|
54
|
+
_evaluate_guardfile
|
55
|
+
|
56
|
+
rows = ::Guard.groups.inject([]) do |rows, group|
|
57
|
+
Array(::Guard.plugins(group: group.name)).each do |plugin|
|
58
|
+
options = plugin.options.inject({}) { |o, (k, v)| o[k.to_s] = v; o }.sort
|
59
|
+
|
60
|
+
if options.empty?
|
61
|
+
rows << :split
|
62
|
+
rows << { Group: group.title, Plugin: plugin.title, Option: '', Value: '' }
|
63
|
+
else
|
64
|
+
options.each_with_index do |(option, value), index|
|
65
|
+
if index == 0
|
66
|
+
rows << :split
|
67
|
+
rows << { Group: group.title, Plugin: plugin.title, Option: option.to_s, Value: value.inspect }
|
68
|
+
else
|
69
|
+
rows << { Group: '', Plugin: '', Option: option.to_s, Value: value.inspect }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
46
73
|
end
|
47
74
|
|
48
|
-
|
75
|
+
rows
|
49
76
|
end
|
50
77
|
|
51
|
-
|
52
|
-
|
53
|
-
#
|
54
|
-
# @param [Hash] options the Guard options
|
55
|
-
#
|
56
|
-
def show(options)
|
57
|
-
evaluate_guardfile(options)
|
58
|
-
|
59
|
-
rows = ::Guard.groups.inject([]) do |rows, group|
|
60
|
-
::Guard.guards({ :group => group.name }).each do |plugin|
|
61
|
-
options = plugin.options.inject({}) { |o, (k, v)| o[k.to_s] = v; o }.sort
|
78
|
+
Formatador.display_compact_table(rows.drop(1), [:Group, :Plugin, :Option, :Value])
|
79
|
+
end
|
62
80
|
|
63
|
-
|
81
|
+
# Shows all notifiers and their options that are defined in
|
82
|
+
# the `Guardfile`.
|
83
|
+
#
|
84
|
+
# @see CLI#show
|
85
|
+
#
|
86
|
+
def notifiers
|
87
|
+
_evaluate_guardfile
|
88
|
+
|
89
|
+
rows = ::Guard::Notifier::NOTIFIERS.inject(:merge).inject([]) do |rows, definition|
|
90
|
+
name = definition[0]
|
91
|
+
clazz = definition[1]
|
92
|
+
available = clazz.available?(silent: true) ? '✔' : '✘'
|
93
|
+
notifier = ::Guard::Notifier.notifiers.find{ |n| n[:name] == name }
|
94
|
+
used = notifier ? '✔' : '✘'
|
95
|
+
options = notifier ? notifier[:options] : {}
|
96
|
+
defaults = clazz.const_defined?(:DEFAULTS) ? clazz.const_get(:DEFAULTS) : {}
|
97
|
+
options = defaults.merge(options)
|
98
|
+
options.delete(:silent)
|
99
|
+
|
100
|
+
if options.empty?
|
101
|
+
rows << :split
|
102
|
+
rows << { Name: name, Available: available, Used: used, Option: '', Value: '' }
|
103
|
+
else
|
104
|
+
options.each_with_index do |(option, value), index|
|
105
|
+
if index == 0
|
64
106
|
rows << :split
|
65
|
-
rows << { :
|
107
|
+
rows << { Name: name, Available: available, Used: used, Option: option.to_s, Value: value.inspect }
|
66
108
|
else
|
67
|
-
|
68
|
-
if index == 0
|
69
|
-
rows << :split
|
70
|
-
rows << { :Group => group.to_s, :Plugin => plugin.to_s, :Option => option.to_s, :Value => value.inspect }
|
71
|
-
else
|
72
|
-
rows << { :Group => '', :Plugin => '', :Option => option.to_s, :Value => value.inspect }
|
73
|
-
end
|
74
|
-
end
|
109
|
+
rows << { Name: '', Available: '', Used: '', Option: option.to_s, Value: value.inspect }
|
75
110
|
end
|
76
111
|
end
|
77
|
-
|
78
|
-
rows
|
79
112
|
end
|
80
113
|
|
81
|
-
|
114
|
+
rows
|
82
115
|
end
|
83
116
|
|
117
|
+
Formatador.display_compact_table(rows.drop(1), [:Name, :Available, :Used, :Option, :Value])
|
84
118
|
end
|
119
|
+
|
120
|
+
private
|
121
|
+
|
122
|
+
# Evaluates the `Guardfile` by delegating to
|
123
|
+
# {Guard::Guardfile::Evaluator#evaluate_guardfile}.
|
124
|
+
#
|
125
|
+
def _evaluate_guardfile
|
126
|
+
::Guard::Guardfile::Evaluator.new(options).evaluate_guardfile
|
127
|
+
end
|
128
|
+
|
85
129
|
end
|
86
130
|
end
|
data/lib/guard/group.rb
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
module Guard
|
2
2
|
|
3
|
-
# A group of Guard plugins. There are two reasons why you want to group your
|
3
|
+
# A group of Guard plugins. There are two reasons why you want to group your
|
4
|
+
# Guard plugins:
|
4
5
|
#
|
5
|
-
#
|
6
|
-
#
|
6
|
+
# * You can start only certain groups from the command line by passing the
|
7
|
+
# `--group` option to `guard start`.
|
8
|
+
# * Abort task execution chain on failure within a group with the
|
9
|
+
# `:halt_on_fail` option.
|
7
10
|
#
|
8
11
|
# @example Group that aborts on failure
|
9
12
|
#
|
10
|
-
# group :frontend, :
|
11
|
-
# guard 'coffeescript', :
|
13
|
+
# group :frontend, halt_on_fail: true do
|
14
|
+
# guard 'coffeescript', input: 'spec/coffeescripts', output: 'spec/javascripts'
|
12
15
|
# guard 'jasmine-headless-webkit' do
|
13
16
|
# watch(%r{^spec/javascripts/(.*)\..*}) { |m| newest_js_file("spec/javascripts/#{m[1]}_spec") }
|
14
17
|
# end
|
@@ -32,12 +35,28 @@ module Guard
|
|
32
35
|
@options = options
|
33
36
|
end
|
34
37
|
|
35
|
-
#
|
38
|
+
# Returns the group title.
|
36
39
|
#
|
37
|
-
# @
|
40
|
+
# @example Title for a group named 'backend'
|
41
|
+
# > Guard::Group.new('backend').title
|
42
|
+
# => "Backend"
|
43
|
+
#
|
44
|
+
# @return [String]
|
45
|
+
#
|
46
|
+
def title
|
47
|
+
@title ||= name.to_s.capitalize
|
48
|
+
end
|
49
|
+
|
50
|
+
# String representation of the group.
|
51
|
+
#
|
52
|
+
# @example String representation of a group named 'backend'
|
53
|
+
# > Guard::Group.new('backend').to_s
|
54
|
+
# => "#<Guard::Group @name=backend @options={}>"
|
55
|
+
#
|
56
|
+
# @return [String] the string representation
|
38
57
|
#
|
39
58
|
def to_s
|
40
|
-
@name
|
59
|
+
"#<#{self.class} @name=#{name} @options=#{options}>"
|
41
60
|
end
|
42
61
|
|
43
62
|
end
|
data/lib/guard/guard.rb
CHANGED
@@ -1,167 +1,42 @@
|
|
1
|
+
require 'guard/plugin/base'
|
2
|
+
|
1
3
|
module Guard
|
2
4
|
|
3
|
-
#
|
4
|
-
#
|
5
|
-
# Guard
|
6
|
-
#
|
7
|
-
# depending on user interaction and file modification.
|
8
|
-
#
|
9
|
-
# `run_on_changes` could be implemented to handle all the changes task case (additions,
|
10
|
-
# modifications, removals) in once, or each task can be implemented separately with a
|
11
|
-
# specific behavior.
|
12
|
-
#
|
13
|
-
# In each of these Guard task methods you have to implement some work when you want to
|
14
|
-
# support this kind of task. The return value of each Guard task method is not evaluated
|
15
|
-
# by Guard, but it'll be passed to the "_end" hook for further evaluation. You can
|
16
|
-
# throw `:task_has_failed` to indicate that your Guard plugin method was not successful,
|
17
|
-
# and successive Guard plugin tasks will be aborted when the group has set the `:halt_on_fail`
|
18
|
-
# option.
|
19
|
-
#
|
20
|
-
# @see Guard::Hook
|
21
|
-
# @see Guard::Group
|
22
|
-
#
|
23
|
-
# @example Throw :task_has_failed
|
24
|
-
#
|
25
|
-
# def run_all
|
26
|
-
# if !runner.run(['all'])
|
27
|
-
# throw :task_has_failed
|
28
|
-
# end
|
29
|
-
# end
|
5
|
+
# @deprecated Inheriting from `Guard::Guard` is deprecated, please inherit
|
6
|
+
# from {Plugin} instead. Please note that the constructor signature has
|
7
|
+
# changed from `Guard::Guard#initialize(watchers = [], options = {})` to
|
8
|
+
# `Guard::Plugin#initialize(options = {})`.
|
30
9
|
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
# By default all watchers for a Guard plugin have to return strings of paths to the
|
35
|
-
# Guard, but if your Guard plugin wants to allow any return value from a watcher,
|
36
|
-
# you can set the `any_return` option to true.
|
37
|
-
#
|
38
|
-
# If one of those methods raise an exception other than `:task_has_failed`,
|
39
|
-
# the Guard::GuardName instance will be removed from the active guards.
|
10
|
+
# @see https://github.com/guard/guard/wiki/Upgrading-to-Guard-2.0 How to
|
11
|
+
# upgrade for Guard 2.0
|
40
12
|
#
|
41
13
|
class Guard
|
42
|
-
|
43
|
-
require 'guard/ui'
|
44
|
-
|
45
|
-
include ::Guard::Hook
|
14
|
+
include ::Guard::Plugin::Base
|
46
15
|
|
47
|
-
|
48
|
-
|
49
|
-
#
|
50
|
-
#
|
16
|
+
# @deprecated Inheriting from `Guard::Guard` is deprecated, please inherit
|
17
|
+
# from {Plugin} instead. Please note that the constructor signature
|
18
|
+
# has changed from `Guard::Guard#initialize(watchers = [], options = {})`
|
19
|
+
# to `Guard::Plugin#initialize(options = {})`.
|
20
|
+
#
|
21
|
+
# Initializes a Guard plugin. Don't do any work here,
|
22
|
+
# especially as Guard plugins get initialized even if they are not in an
|
23
|
+
# active group!
|
24
|
+
#
|
25
|
+
# @see https://github.com/guard/guard/wiki/Upgrading-to-Guard-2.0 How to
|
26
|
+
# upgrade for Guard 2.0
|
51
27
|
#
|
52
28
|
# @param [Array<Guard::Watcher>] watchers the Guard plugin file watchers
|
53
29
|
# @param [Hash] options the custom Guard plugin options
|
54
30
|
# @option options [Symbol] group the group this Guard plugin belongs to
|
55
|
-
# @option options [Boolean] any_return allow any object to be returned from
|
31
|
+
# @option options [Boolean] any_return allow any object to be returned from
|
32
|
+
# a watcher
|
56
33
|
#
|
57
34
|
def initialize(watchers = [], options = {})
|
58
|
-
|
59
|
-
@watchers, @options = watchers, options
|
60
|
-
end
|
35
|
+
::Guard::UI.deprecation(::Guard::Deprecator::GUARD_GUARD_DEPRECATION % title)
|
61
36
|
|
62
|
-
|
63
|
-
|
64
|
-
#
|
65
|
-
# @param [String] The plugin name
|
66
|
-
#
|
67
|
-
def self.template(name)
|
68
|
-
File.read("#{ ::Guard.locate_guard(name) }/lib/guard/#{ name }/templates/Guardfile")
|
69
|
-
end
|
70
|
-
|
71
|
-
# Initialize the Guard plugin. This will copy the Guardfile template inside the Guard plugin Gem.
|
72
|
-
# The template Guardfile must be located within the Gem at `lib/guard/guard-name/templates/Guardfile`.
|
73
|
-
#
|
74
|
-
# @param [String] name the name of the Guard plugin
|
75
|
-
#
|
76
|
-
def self.init(name)
|
77
|
-
if ::Guard::Dsl.guardfile_include?(name)
|
78
|
-
::Guard::UI.info "Guardfile already includes #{ name } guard"
|
79
|
-
else
|
80
|
-
content = File.read('Guardfile')
|
81
|
-
guard = template(name)
|
82
|
-
|
83
|
-
File.open('Guardfile', 'wb') do |f|
|
84
|
-
f.puts(content)
|
85
|
-
f.puts("")
|
86
|
-
f.puts(guard)
|
87
|
-
end
|
88
|
-
|
89
|
-
::Guard::UI.info "#{ name } guard added to Guardfile, feel free to edit it"
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
# Called once when Guard starts. Please override initialize method to init stuff.
|
94
|
-
#
|
95
|
-
# @raise [:task_has_failed] when start has failed
|
96
|
-
# @return [Object] the task result
|
97
|
-
#
|
98
|
-
# @!method start
|
99
|
-
|
100
|
-
# Called when `stop|quit|exit|s|q|e + enter` is pressed (when Guard quits).
|
101
|
-
#
|
102
|
-
# @raise [:task_has_failed] when stop has failed
|
103
|
-
# @return [Object] the task result
|
104
|
-
#
|
105
|
-
# @!method stop
|
106
|
-
|
107
|
-
# Called when `reload|r|z + enter` is pressed.
|
108
|
-
# This method should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/...
|
109
|
-
#
|
110
|
-
# @raise [:task_has_failed] when reload has failed
|
111
|
-
# @return [Object] the task result
|
112
|
-
#
|
113
|
-
# @!method reload
|
114
|
-
|
115
|
-
# Called when just `enter` is pressed
|
116
|
-
# This method should be principally used for long action like running all specs/tests/...
|
117
|
-
#
|
118
|
-
# @raise [:task_has_failed] when run_all has failed
|
119
|
-
# @return [Object] the task result
|
120
|
-
#
|
121
|
-
# @!method run_all
|
122
|
-
|
123
|
-
# Default behaviour on file(s) changes that the Guard plugin watches.
|
124
|
-
#
|
125
|
-
# @param [Array<String>] paths the changes files or paths
|
126
|
-
# @raise [:task_has_failed] when run_on_changes has failed
|
127
|
-
# @return [Object] the task result
|
128
|
-
#
|
129
|
-
# @!method run_on_changes(paths)
|
130
|
-
|
131
|
-
# Called on file(s) additions that the Guard plugin watches.
|
132
|
-
#
|
133
|
-
# @param [Array<String>] paths the changes files or paths
|
134
|
-
# @raise [:task_has_failed] when run_on_additions has failed
|
135
|
-
# @return [Object] the task result
|
136
|
-
#
|
137
|
-
# @!method run_on_additions(paths)
|
138
|
-
|
139
|
-
# Called on file(s) modifications that the Guard plugin watches.
|
140
|
-
#
|
141
|
-
# @param [Array<String>] paths the changes files or paths
|
142
|
-
# @raise [:task_has_failed] when run_on_modifications has failed
|
143
|
-
# @return [Object] the task result
|
144
|
-
#
|
145
|
-
# @!method run_on_modifications(paths)
|
146
|
-
|
147
|
-
# Called on file(s) removals that the Guard plugin watches.
|
148
|
-
#
|
149
|
-
# @param [Array<String>] paths the changes files or paths
|
150
|
-
# @raise [:task_has_failed] when run_on_removals has failed
|
151
|
-
# @return [Object] the task result
|
152
|
-
#
|
153
|
-
# @!method run_on_removals(paths)
|
154
|
-
|
155
|
-
# Convert plugin to string representation. The
|
156
|
-
# default just uses the plugin class name and
|
157
|
-
# removes the Guard module name.
|
158
|
-
#
|
159
|
-
# @return [String] the string representation
|
160
|
-
#
|
161
|
-
def to_s
|
162
|
-
self.class.to_s.downcase.sub('guard::', '').capitalize
|
37
|
+
_set_instance_variables_from_options(options.merge(watchers: watchers))
|
38
|
+
_register_callbacks
|
163
39
|
end
|
164
40
|
|
165
41
|
end
|
166
|
-
|
167
42
|
end
|
data/lib/guard/guardfile.rb
CHANGED
@@ -1,94 +1,44 @@
|
|
1
|
+
require 'guard/guardfile/evaluator'
|
2
|
+
require 'guard/guardfile/generator'
|
3
|
+
require 'guard/ui'
|
4
|
+
|
1
5
|
module Guard
|
2
6
|
|
3
|
-
#
|
4
|
-
#
|
7
|
+
# @deprecated Use instance methods of {Guardfile::Evaluator} and
|
8
|
+
# {Guardfile::Generator} instead.
|
5
9
|
#
|
6
|
-
# @see
|
10
|
+
# @see Guardfile::Evaluator
|
11
|
+
# @see Guardfile::Generator
|
7
12
|
#
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
# @see Guard::CLI.init
|
19
|
-
#
|
20
|
-
# @param [Hash] options The options for creating a Guardfile
|
21
|
-
# @option options [Boolean] :abort_on_existence Whether to abort or not when a Guardfile already exists
|
22
|
-
#
|
23
|
-
def create_guardfile(options = {})
|
24
|
-
if !File.exist?('Guardfile')
|
25
|
-
::Guard::UI.info "Writing new Guardfile to #{ Dir.pwd }/Guardfile"
|
26
|
-
FileUtils.cp(GUARDFILE_TEMPLATE, 'Guardfile')
|
27
|
-
elsif options[:abort_on_existence]
|
28
|
-
::Guard::UI.error "Guardfile already exists at #{ Dir.pwd }/Guardfile"
|
29
|
-
abort
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# Opens an existing guardfile and searches for redundant definitions
|
34
|
-
# if extraneous defintions are found, it warns the user
|
35
|
-
#
|
36
|
-
# @see Guard::CLI.init
|
37
|
-
#
|
38
|
-
# @param [String] class name of gem definition that you would like to search for in the Guardfile
|
39
|
-
# @param [String] contents of existing guardfile
|
40
|
-
#
|
41
|
-
def duplicate_definitions?(guard_class, guard_file)
|
42
|
-
matches = guard_file.to_s.scan(/guard\s[\'|\"]#{guard_class}[\'|\"]\sdo/)
|
43
|
-
if matches.count > 1
|
44
|
-
::Guard::UI.info "There are #{matches.count.to_s} definitions in your Guardfile for '#{guard_class}', you may want to clean up your Guardfile as this could cause issues."
|
45
|
-
return true
|
46
|
-
else
|
47
|
-
return false
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
# Adds the Guardfile template of a Guard implementation
|
52
|
-
# to an existing Guardfile.
|
53
|
-
#
|
54
|
-
# @see Guard::CLI.init
|
55
|
-
#
|
56
|
-
# @param [String] guard_name the name of the Guard or template to initialize
|
57
|
-
#
|
58
|
-
def initialize_template(guard_name)
|
59
|
-
guard_class = ::Guard.get_guard_class(guard_name, true)
|
60
|
-
|
61
|
-
if guard_class
|
62
|
-
guard_class.init(guard_name)
|
63
|
-
guardfile_name = 'Guardfile'
|
64
|
-
guard_file = File.read(guardfile_name) if File.exists?(guardfile_name)
|
65
|
-
duplicate_definitions?(guard_name, guard_file)
|
66
|
-
elsif File.exist?(File.join(HOME_TEMPLATES, guard_name))
|
67
|
-
content = File.read('Guardfile')
|
68
|
-
template = File.read(File.join(HOME_TEMPLATES, guard_name))
|
69
|
-
|
70
|
-
File.open('Guardfile', 'wb') do |f|
|
71
|
-
f.puts(content)
|
72
|
-
f.puts('')
|
73
|
-
f.puts(template)
|
74
|
-
end
|
75
|
-
|
76
|
-
::Guard::UI.info "#{ guard_name } template added to Guardfile, feel free to edit it"
|
77
|
-
else
|
78
|
-
const_name = guard_name.downcase.gsub('-', '')
|
79
|
-
UI.error "Could not load 'guard/#{ guard_name.downcase }' or '~/.guard/templates/#{ guard_name.downcase }' or find class Guard::#{ const_name.capitalize }"
|
80
|
-
end
|
81
|
-
end
|
13
|
+
module Guardfile
|
14
|
+
|
15
|
+
# @deprecated Use {Guardfile::Generator#create_guardfile} instead.
|
16
|
+
#
|
17
|
+
# @see https://github.com/guard/guard/wiki/Upgrading-to-Guard-2.0 How to upgrade for Guard 2.0
|
18
|
+
#
|
19
|
+
def self.create_guardfile(options = {})
|
20
|
+
::Guard::UI.deprecation(::Guard::Deprecator::CREATE_GUARDFILE_DEPRECATION)
|
21
|
+
Generator.new(options).create_guardfile
|
22
|
+
end
|
82
23
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
24
|
+
# @deprecated Use {Guardfile::Generator#initialize_template} instead.
|
25
|
+
#
|
26
|
+
# @see https://github.com/guard/guard/wiki/Upgrading-to-Guard-2.0 How to upgrade for Guard 2.0
|
27
|
+
#
|
28
|
+
def self.initialize_template(plugin_name)
|
29
|
+
::Guard::UI.deprecation(::Guard::Deprecator::INITIALIZE_TEMPLATE_DEPRECATION)
|
30
|
+
Generator.new.initialize_template(plugin_name)
|
31
|
+
end
|
91
32
|
|
33
|
+
# @deprecated Use {Guardfile::Generator#initialize_all_templates} instead.
|
34
|
+
#
|
35
|
+
# @see https://github.com/guard/guard/wiki/Upgrading-to-Guard-2.0 How to upgrade for Guard 2.0
|
36
|
+
#
|
37
|
+
def self.initialize_all_templates
|
38
|
+
::Guard::UI.deprecation(::Guard::Deprecator::INITIALIZE_ALL_TEMPLATES_DEPRECATION)
|
39
|
+
Generator.new.initialize_all_templates
|
92
40
|
end
|
41
|
+
|
93
42
|
end
|
43
|
+
|
94
44
|
end
|