honeybadger 5.0.2 → 5.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +718 -701
- data/LICENSE +19 -19
- data/README.md +57 -57
- data/TROUBLESHOOTING.md +3 -3
- data/bin/honeybadger +5 -5
- data/lib/honeybadger/agent.rb +488 -488
- data/lib/honeybadger/backend/base.rb +116 -116
- data/lib/honeybadger/backend/debug.rb +22 -22
- data/lib/honeybadger/backend/null.rb +29 -29
- data/lib/honeybadger/backend/server.rb +62 -62
- data/lib/honeybadger/backend/test.rb +46 -46
- data/lib/honeybadger/backend.rb +27 -27
- data/lib/honeybadger/backtrace.rb +181 -181
- data/lib/honeybadger/breadcrumbs/active_support.rb +119 -119
- data/lib/honeybadger/breadcrumbs/breadcrumb.rb +53 -53
- data/lib/honeybadger/breadcrumbs/collector.rb +82 -82
- data/lib/honeybadger/breadcrumbs/logging.rb +55 -51
- data/lib/honeybadger/breadcrumbs/ring_buffer.rb +44 -44
- data/lib/honeybadger/breadcrumbs.rb +8 -8
- data/lib/honeybadger/cli/deploy.rb +43 -43
- data/lib/honeybadger/cli/exec.rb +143 -143
- data/lib/honeybadger/cli/helpers.rb +28 -28
- data/lib/honeybadger/cli/heroku.rb +129 -129
- data/lib/honeybadger/cli/install.rb +101 -101
- data/lib/honeybadger/cli/main.rb +237 -237
- data/lib/honeybadger/cli/notify.rb +67 -67
- data/lib/honeybadger/cli/test.rb +267 -267
- data/lib/honeybadger/cli.rb +14 -14
- data/lib/honeybadger/config/defaults.rb +336 -333
- data/lib/honeybadger/config/env.rb +42 -42
- data/lib/honeybadger/config/ruby.rb +146 -146
- data/lib/honeybadger/config/yaml.rb +76 -76
- data/lib/honeybadger/config.rb +416 -413
- data/lib/honeybadger/const.rb +20 -20
- data/lib/honeybadger/context_manager.rb +55 -55
- data/lib/honeybadger/conversions.rb +16 -16
- data/lib/honeybadger/init/hanami.rb +19 -0
- data/lib/honeybadger/init/rails.rb +38 -38
- data/lib/honeybadger/init/rake.rb +66 -66
- data/lib/honeybadger/init/ruby.rb +11 -11
- data/lib/honeybadger/init/sinatra.rb +57 -51
- data/lib/honeybadger/logging.rb +177 -177
- data/lib/honeybadger/notice.rb +579 -568
- data/lib/honeybadger/plugin.rb +210 -210
- data/lib/honeybadger/plugins/breadcrumbs.rb +111 -111
- data/lib/honeybadger/plugins/delayed_job/plugin.rb +56 -56
- data/lib/honeybadger/plugins/delayed_job.rb +22 -22
- data/lib/honeybadger/plugins/faktory.rb +52 -52
- data/lib/honeybadger/plugins/lambda.rb +71 -71
- data/lib/honeybadger/plugins/local_variables.rb +44 -44
- data/lib/honeybadger/plugins/passenger.rb +23 -23
- data/lib/honeybadger/plugins/rails.rb +72 -63
- data/lib/honeybadger/plugins/resque.rb +72 -72
- data/lib/honeybadger/plugins/shoryuken.rb +52 -52
- data/lib/honeybadger/plugins/sidekiq.rb +71 -62
- data/lib/honeybadger/plugins/sucker_punch.rb +18 -18
- data/lib/honeybadger/plugins/thor.rb +32 -32
- data/lib/honeybadger/plugins/warden.rb +19 -19
- data/lib/honeybadger/rack/error_notifier.rb +92 -92
- data/lib/honeybadger/rack/user_feedback.rb +88 -88
- data/lib/honeybadger/rack/user_informer.rb +45 -45
- data/lib/honeybadger/ruby.rb +2 -2
- data/lib/honeybadger/singleton.rb +103 -103
- data/lib/honeybadger/tasks.rb +22 -22
- data/lib/honeybadger/templates/feedback_form.erb +84 -84
- data/lib/honeybadger/util/http.rb +92 -92
- data/lib/honeybadger/util/lambda.rb +32 -32
- data/lib/honeybadger/util/request_hash.rb +73 -73
- data/lib/honeybadger/util/request_payload.rb +41 -41
- data/lib/honeybadger/util/revision.rb +39 -39
- data/lib/honeybadger/util/sanitizer.rb +214 -214
- data/lib/honeybadger/util/sql.rb +34 -34
- data/lib/honeybadger/util/stats.rb +50 -50
- data/lib/honeybadger/version.rb +4 -4
- data/lib/honeybadger/worker.rb +253 -253
- data/lib/honeybadger.rb +13 -11
- data/resources/ca-bundle.crt +3376 -3376
- data/vendor/capistrano-honeybadger/lib/capistrano/honeybadger.rb +5 -5
- data/vendor/capistrano-honeybadger/lib/capistrano/tasks/deploy.cap +89 -89
- data/vendor/capistrano-honeybadger/lib/honeybadger/capistrano/legacy.rb +47 -47
- data/vendor/capistrano-honeybadger/lib/honeybadger/capistrano.rb +2 -2
- data/vendor/cli/inifile.rb +628 -628
- data/vendor/cli/thor/actions/create_file.rb +103 -103
- data/vendor/cli/thor/actions/create_link.rb +59 -59
- data/vendor/cli/thor/actions/directory.rb +118 -118
- data/vendor/cli/thor/actions/empty_directory.rb +135 -135
- data/vendor/cli/thor/actions/file_manipulation.rb +316 -316
- data/vendor/cli/thor/actions/inject_into_file.rb +107 -107
- data/vendor/cli/thor/actions.rb +319 -319
- data/vendor/cli/thor/base.rb +656 -656
- data/vendor/cli/thor/command.rb +133 -133
- data/vendor/cli/thor/core_ext/hash_with_indifferent_access.rb +77 -77
- data/vendor/cli/thor/core_ext/io_binary_read.rb +10 -10
- data/vendor/cli/thor/core_ext/ordered_hash.rb +98 -98
- data/vendor/cli/thor/error.rb +32 -32
- data/vendor/cli/thor/group.rb +281 -281
- data/vendor/cli/thor/invocation.rb +178 -178
- data/vendor/cli/thor/line_editor/basic.rb +35 -35
- data/vendor/cli/thor/line_editor/readline.rb +88 -88
- data/vendor/cli/thor/line_editor.rb +17 -17
- data/vendor/cli/thor/parser/argument.rb +73 -73
- data/vendor/cli/thor/parser/arguments.rb +175 -175
- data/vendor/cli/thor/parser/option.rb +125 -125
- data/vendor/cli/thor/parser/options.rb +218 -218
- data/vendor/cli/thor/parser.rb +4 -4
- data/vendor/cli/thor/rake_compat.rb +71 -71
- data/vendor/cli/thor/runner.rb +322 -322
- data/vendor/cli/thor/shell/basic.rb +421 -421
- data/vendor/cli/thor/shell/color.rb +149 -149
- data/vendor/cli/thor/shell/html.rb +126 -126
- data/vendor/cli/thor/shell.rb +81 -81
- data/vendor/cli/thor/util.rb +267 -267
- data/vendor/cli/thor/version.rb +3 -3
- data/vendor/cli/thor.rb +484 -484
- metadata +11 -5
data/vendor/cli/thor/actions.rb
CHANGED
@@ -1,319 +1,319 @@
|
|
1
|
-
require "fileutils"
|
2
|
-
require "uri"
|
3
|
-
require "thor/core_ext/io_binary_read"
|
4
|
-
require "thor/actions/create_file"
|
5
|
-
require "thor/actions/create_link"
|
6
|
-
require "thor/actions/directory"
|
7
|
-
require "thor/actions/empty_directory"
|
8
|
-
require "thor/actions/file_manipulation"
|
9
|
-
require "thor/actions/inject_into_file"
|
10
|
-
|
11
|
-
class Thor
|
12
|
-
module Actions
|
13
|
-
attr_accessor :behavior
|
14
|
-
|
15
|
-
def self.included(base) #:nodoc:
|
16
|
-
base.extend ClassMethods
|
17
|
-
end
|
18
|
-
|
19
|
-
module ClassMethods
|
20
|
-
# Hold source paths for one Thor instance. source_paths_for_search is the
|
21
|
-
# method responsible to gather source_paths from this current class,
|
22
|
-
# inherited paths and the source root.
|
23
|
-
#
|
24
|
-
def source_paths
|
25
|
-
@_source_paths ||= []
|
26
|
-
end
|
27
|
-
|
28
|
-
# Stores and return the source root for this class
|
29
|
-
def source_root(path = nil)
|
30
|
-
@_source_root = path if path
|
31
|
-
@_source_root ||= nil
|
32
|
-
end
|
33
|
-
|
34
|
-
# Returns the source paths in the following order:
|
35
|
-
#
|
36
|
-
# 1) This class source paths
|
37
|
-
# 2) Source root
|
38
|
-
# 3) Parents source paths
|
39
|
-
#
|
40
|
-
def source_paths_for_search
|
41
|
-
paths = []
|
42
|
-
paths += source_paths
|
43
|
-
paths << source_root if source_root
|
44
|
-
paths += from_superclass(:source_paths, [])
|
45
|
-
paths
|
46
|
-
end
|
47
|
-
|
48
|
-
# Add runtime options that help actions execution.
|
49
|
-
#
|
50
|
-
def add_runtime_options!
|
51
|
-
class_option :force, :type => :boolean, :aliases => "-f", :group => :runtime,
|
52
|
-
:desc => "Overwrite files that already exist"
|
53
|
-
|
54
|
-
class_option :pretend, :type => :boolean, :aliases => "-p", :group => :runtime,
|
55
|
-
:desc => "Run but do not make any changes"
|
56
|
-
|
57
|
-
class_option :quiet, :type => :boolean, :aliases => "-q", :group => :runtime,
|
58
|
-
:desc => "Suppress status output"
|
59
|
-
|
60
|
-
class_option :skip, :type => :boolean, :aliases => "-s", :group => :runtime,
|
61
|
-
:desc => "Skip files that already exist"
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
# Extends initializer to add more configuration options.
|
66
|
-
#
|
67
|
-
# ==== Configuration
|
68
|
-
# behavior<Symbol>:: The actions default behavior. Can be :invoke or :revoke.
|
69
|
-
# It also accepts :force, :skip and :pretend to set the behavior
|
70
|
-
# and the respective option.
|
71
|
-
#
|
72
|
-
# destination_root<String>:: The root directory needed for some actions.
|
73
|
-
#
|
74
|
-
def initialize(args = [], options = {}, config = {})
|
75
|
-
self.behavior = case config[:behavior].to_s
|
76
|
-
when "force", "skip"
|
77
|
-
_cleanup_options_and_set(options, config[:behavior])
|
78
|
-
:invoke
|
79
|
-
when "revoke"
|
80
|
-
:revoke
|
81
|
-
else
|
82
|
-
:invoke
|
83
|
-
end
|
84
|
-
super
|
85
|
-
self.destination_root = config[:destination_root]
|
86
|
-
end
|
87
|
-
|
88
|
-
# Wraps an action object and call it accordingly to the thor class behavior.
|
89
|
-
#
|
90
|
-
def action(instance) #:nodoc:
|
91
|
-
if behavior == :revoke
|
92
|
-
instance.revoke!
|
93
|
-
else
|
94
|
-
instance.invoke!
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
# Returns the root for this thor class (also aliased as destination root).
|
99
|
-
#
|
100
|
-
def destination_root
|
101
|
-
@destination_stack.last
|
102
|
-
end
|
103
|
-
|
104
|
-
# Sets the root for this thor class. Relatives path are added to the
|
105
|
-
# directory where the script was invoked and expanded.
|
106
|
-
#
|
107
|
-
def destination_root=(root)
|
108
|
-
@destination_stack ||= []
|
109
|
-
@destination_stack[0] = File.expand_path(root || "")
|
110
|
-
end
|
111
|
-
|
112
|
-
# Returns the given path relative to the absolute root (ie, root where
|
113
|
-
# the script started).
|
114
|
-
#
|
115
|
-
def relative_to_original_destination_root(path, remove_dot = true)
|
116
|
-
path = path.dup
|
117
|
-
if path.gsub!(@destination_stack[0], ".")
|
118
|
-
remove_dot ? (path[2..-1] || "") : path
|
119
|
-
else
|
120
|
-
path
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
# Holds source paths in instance so they can be manipulated.
|
125
|
-
#
|
126
|
-
def source_paths
|
127
|
-
@source_paths ||= self.class.source_paths_for_search
|
128
|
-
end
|
129
|
-
|
130
|
-
# Receives a file or directory and search for it in the source paths.
|
131
|
-
#
|
132
|
-
def find_in_source_paths(file) # rubocop:disable MethodLength
|
133
|
-
possible_files = [file, file + TEMPLATE_EXTNAME]
|
134
|
-
relative_root = relative_to_original_destination_root(destination_root, false)
|
135
|
-
|
136
|
-
source_paths.each do |source|
|
137
|
-
possible_files.each do |f|
|
138
|
-
source_file = File.expand_path(f, File.join(source, relative_root))
|
139
|
-
return source_file if File.exist?(source_file)
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
message = "Could not find #{file.inspect} in any of your source paths. "
|
144
|
-
|
145
|
-
unless self.class.source_root
|
146
|
-
message << "Please invoke #{self.class.name}.source_root(PATH) with the PATH containing your templates. "
|
147
|
-
end
|
148
|
-
|
149
|
-
if source_paths.empty?
|
150
|
-
message << "Currently you have no source paths."
|
151
|
-
else
|
152
|
-
message << "Your current source paths are: \n#{source_paths.join("\n")}"
|
153
|
-
end
|
154
|
-
|
155
|
-
fail Error, message
|
156
|
-
end
|
157
|
-
|
158
|
-
# Do something in the root or on a provided subfolder. If a relative path
|
159
|
-
# is given it's referenced from the current root. The full path is yielded
|
160
|
-
# to the block you provide. The path is set back to the previous path when
|
161
|
-
# the method exits.
|
162
|
-
#
|
163
|
-
# ==== Parameters
|
164
|
-
# dir<String>:: the directory to move to.
|
165
|
-
# config<Hash>:: give :verbose => true to log and use padding.
|
166
|
-
#
|
167
|
-
def inside(dir = "", config = {}, &block)
|
168
|
-
verbose = config.fetch(:verbose, false)
|
169
|
-
pretend = options[:pretend]
|
170
|
-
|
171
|
-
say_status :inside, dir, verbose
|
172
|
-
shell.padding += 1 if verbose
|
173
|
-
@destination_stack.push File.expand_path(dir, destination_root)
|
174
|
-
|
175
|
-
# If the directory doesnt exist and we're not pretending
|
176
|
-
if !File.exist?(destination_root) && !pretend
|
177
|
-
FileUtils.mkdir_p(destination_root)
|
178
|
-
end
|
179
|
-
|
180
|
-
if pretend
|
181
|
-
# In pretend mode, just yield down to the block
|
182
|
-
block.arity == 1 ? yield(destination_root) : yield
|
183
|
-
else
|
184
|
-
FileUtils.cd(destination_root) { block.arity == 1 ? yield(destination_root) : yield }
|
185
|
-
end
|
186
|
-
|
187
|
-
@destination_stack.pop
|
188
|
-
shell.padding -= 1 if verbose
|
189
|
-
end
|
190
|
-
|
191
|
-
# Goes to the root and execute the given block.
|
192
|
-
#
|
193
|
-
def in_root
|
194
|
-
inside(@destination_stack.first) { yield }
|
195
|
-
end
|
196
|
-
|
197
|
-
# Loads an external file and execute it in the instance binding.
|
198
|
-
#
|
199
|
-
# ==== Parameters
|
200
|
-
# path<String>:: The path to the file to execute. Can be a web address or
|
201
|
-
# a relative path from the source root.
|
202
|
-
#
|
203
|
-
# ==== Examples
|
204
|
-
#
|
205
|
-
# apply "http://gist.github.com/103208"
|
206
|
-
#
|
207
|
-
# apply "recipes/jquery.rb"
|
208
|
-
#
|
209
|
-
def apply(path, config = {})
|
210
|
-
verbose = config.fetch(:verbose, true)
|
211
|
-
is_uri = path =~ %r{^https?\://}
|
212
|
-
path = find_in_source_paths(path) unless is_uri
|
213
|
-
|
214
|
-
say_status :apply, path, verbose
|
215
|
-
shell.padding += 1 if verbose
|
216
|
-
|
217
|
-
if is_uri
|
218
|
-
contents = open(path, "Accept" => "application/x-thor-template") { |io| io.read }
|
219
|
-
else
|
220
|
-
contents = open(path) { |io| io.read }
|
221
|
-
end
|
222
|
-
|
223
|
-
instance_eval(contents, path)
|
224
|
-
shell.padding -= 1 if verbose
|
225
|
-
end
|
226
|
-
|
227
|
-
# Executes a command returning the contents of the command.
|
228
|
-
#
|
229
|
-
# ==== Parameters
|
230
|
-
# command<String>:: the command to be executed.
|
231
|
-
# config<Hash>:: give :verbose => false to not log the status, :capture => true to hide to output. Specify :with
|
232
|
-
# to append an executable to command execution.
|
233
|
-
#
|
234
|
-
# ==== Example
|
235
|
-
#
|
236
|
-
# inside('vendor') do
|
237
|
-
# run('ln -s ~/edge rails')
|
238
|
-
# end
|
239
|
-
#
|
240
|
-
def run(command, config = {})
|
241
|
-
return unless behavior == :invoke
|
242
|
-
|
243
|
-
destination = relative_to_original_destination_root(destination_root, false)
|
244
|
-
desc = "#{command} from #{destination.inspect}"
|
245
|
-
|
246
|
-
if config[:with]
|
247
|
-
desc = "#{File.basename(config[:with].to_s)} #{desc}"
|
248
|
-
command = "#{config[:with]} #{command}"
|
249
|
-
end
|
250
|
-
|
251
|
-
say_status :run, desc, config.fetch(:verbose, true)
|
252
|
-
|
253
|
-
unless options[:pretend]
|
254
|
-
config[:capture] ? `#{command}` : system("#{command}")
|
255
|
-
end
|
256
|
-
end
|
257
|
-
|
258
|
-
# Executes a ruby script (taking into account WIN32 platform quirks).
|
259
|
-
#
|
260
|
-
# ==== Parameters
|
261
|
-
# command<String>:: the command to be executed.
|
262
|
-
# config<Hash>:: give :verbose => false to not log the status.
|
263
|
-
#
|
264
|
-
def run_ruby_script(command, config = {})
|
265
|
-
return unless behavior == :invoke
|
266
|
-
run command, config.merge(:with => Thor::Util.ruby_command)
|
267
|
-
end
|
268
|
-
|
269
|
-
# Run a thor command. A hash of options can be given and it's converted to
|
270
|
-
# switches.
|
271
|
-
#
|
272
|
-
# ==== Parameters
|
273
|
-
# command<String>:: the command to be invoked
|
274
|
-
# args<Array>:: arguments to the command
|
275
|
-
# config<Hash>:: give :verbose => false to not log the status, :capture => true to hide to output.
|
276
|
-
# Other options are given as parameter to Thor.
|
277
|
-
#
|
278
|
-
#
|
279
|
-
# ==== Examples
|
280
|
-
#
|
281
|
-
# thor :install, "http://gist.github.com/103208"
|
282
|
-
# #=> thor install http://gist.github.com/103208
|
283
|
-
#
|
284
|
-
# thor :list, :all => true, :substring => 'rails'
|
285
|
-
# #=> thor list --all --substring=rails
|
286
|
-
#
|
287
|
-
def thor(command, *args)
|
288
|
-
config = args.last.is_a?(Hash) ? args.pop : {}
|
289
|
-
verbose = config.key?(:verbose) ? config.delete(:verbose) : true
|
290
|
-
pretend = config.key?(:pretend) ? config.delete(:pretend) : false
|
291
|
-
capture = config.key?(:capture) ? config.delete(:capture) : false
|
292
|
-
|
293
|
-
args.unshift(command)
|
294
|
-
args.push Thor::Options.to_switches(config)
|
295
|
-
command = args.join(" ").strip
|
296
|
-
|
297
|
-
run command, :with => :thor, :verbose => verbose, :pretend => pretend, :capture => capture
|
298
|
-
end
|
299
|
-
|
300
|
-
protected
|
301
|
-
|
302
|
-
# Allow current root to be shared between invocations.
|
303
|
-
#
|
304
|
-
def _shared_configuration #:nodoc:
|
305
|
-
super.merge!(:destination_root => destination_root)
|
306
|
-
end
|
307
|
-
|
308
|
-
def _cleanup_options_and_set(options, key) #:nodoc:
|
309
|
-
case options
|
310
|
-
when Array
|
311
|
-
%w[--force -f --skip -s].each { |i| options.delete(i) }
|
312
|
-
options << "--#{key}"
|
313
|
-
when Hash
|
314
|
-
[:force, :skip, "force", "skip"].each { |i| options.delete(i) }
|
315
|
-
options.merge!(key => true)
|
316
|
-
end
|
317
|
-
end
|
318
|
-
end
|
319
|
-
end
|
1
|
+
require "fileutils"
|
2
|
+
require "uri"
|
3
|
+
require "thor/core_ext/io_binary_read"
|
4
|
+
require "thor/actions/create_file"
|
5
|
+
require "thor/actions/create_link"
|
6
|
+
require "thor/actions/directory"
|
7
|
+
require "thor/actions/empty_directory"
|
8
|
+
require "thor/actions/file_manipulation"
|
9
|
+
require "thor/actions/inject_into_file"
|
10
|
+
|
11
|
+
class Thor
|
12
|
+
module Actions
|
13
|
+
attr_accessor :behavior
|
14
|
+
|
15
|
+
def self.included(base) #:nodoc:
|
16
|
+
base.extend ClassMethods
|
17
|
+
end
|
18
|
+
|
19
|
+
module ClassMethods
|
20
|
+
# Hold source paths for one Thor instance. source_paths_for_search is the
|
21
|
+
# method responsible to gather source_paths from this current class,
|
22
|
+
# inherited paths and the source root.
|
23
|
+
#
|
24
|
+
def source_paths
|
25
|
+
@_source_paths ||= []
|
26
|
+
end
|
27
|
+
|
28
|
+
# Stores and return the source root for this class
|
29
|
+
def source_root(path = nil)
|
30
|
+
@_source_root = path if path
|
31
|
+
@_source_root ||= nil
|
32
|
+
end
|
33
|
+
|
34
|
+
# Returns the source paths in the following order:
|
35
|
+
#
|
36
|
+
# 1) This class source paths
|
37
|
+
# 2) Source root
|
38
|
+
# 3) Parents source paths
|
39
|
+
#
|
40
|
+
def source_paths_for_search
|
41
|
+
paths = []
|
42
|
+
paths += source_paths
|
43
|
+
paths << source_root if source_root
|
44
|
+
paths += from_superclass(:source_paths, [])
|
45
|
+
paths
|
46
|
+
end
|
47
|
+
|
48
|
+
# Add runtime options that help actions execution.
|
49
|
+
#
|
50
|
+
def add_runtime_options!
|
51
|
+
class_option :force, :type => :boolean, :aliases => "-f", :group => :runtime,
|
52
|
+
:desc => "Overwrite files that already exist"
|
53
|
+
|
54
|
+
class_option :pretend, :type => :boolean, :aliases => "-p", :group => :runtime,
|
55
|
+
:desc => "Run but do not make any changes"
|
56
|
+
|
57
|
+
class_option :quiet, :type => :boolean, :aliases => "-q", :group => :runtime,
|
58
|
+
:desc => "Suppress status output"
|
59
|
+
|
60
|
+
class_option :skip, :type => :boolean, :aliases => "-s", :group => :runtime,
|
61
|
+
:desc => "Skip files that already exist"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# Extends initializer to add more configuration options.
|
66
|
+
#
|
67
|
+
# ==== Configuration
|
68
|
+
# behavior<Symbol>:: The actions default behavior. Can be :invoke or :revoke.
|
69
|
+
# It also accepts :force, :skip and :pretend to set the behavior
|
70
|
+
# and the respective option.
|
71
|
+
#
|
72
|
+
# destination_root<String>:: The root directory needed for some actions.
|
73
|
+
#
|
74
|
+
def initialize(args = [], options = {}, config = {})
|
75
|
+
self.behavior = case config[:behavior].to_s
|
76
|
+
when "force", "skip"
|
77
|
+
_cleanup_options_and_set(options, config[:behavior])
|
78
|
+
:invoke
|
79
|
+
when "revoke"
|
80
|
+
:revoke
|
81
|
+
else
|
82
|
+
:invoke
|
83
|
+
end
|
84
|
+
super
|
85
|
+
self.destination_root = config[:destination_root]
|
86
|
+
end
|
87
|
+
|
88
|
+
# Wraps an action object and call it accordingly to the thor class behavior.
|
89
|
+
#
|
90
|
+
def action(instance) #:nodoc:
|
91
|
+
if behavior == :revoke
|
92
|
+
instance.revoke!
|
93
|
+
else
|
94
|
+
instance.invoke!
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# Returns the root for this thor class (also aliased as destination root).
|
99
|
+
#
|
100
|
+
def destination_root
|
101
|
+
@destination_stack.last
|
102
|
+
end
|
103
|
+
|
104
|
+
# Sets the root for this thor class. Relatives path are added to the
|
105
|
+
# directory where the script was invoked and expanded.
|
106
|
+
#
|
107
|
+
def destination_root=(root)
|
108
|
+
@destination_stack ||= []
|
109
|
+
@destination_stack[0] = File.expand_path(root || "")
|
110
|
+
end
|
111
|
+
|
112
|
+
# Returns the given path relative to the absolute root (ie, root where
|
113
|
+
# the script started).
|
114
|
+
#
|
115
|
+
def relative_to_original_destination_root(path, remove_dot = true)
|
116
|
+
path = path.dup
|
117
|
+
if path.gsub!(@destination_stack[0], ".")
|
118
|
+
remove_dot ? (path[2..-1] || "") : path
|
119
|
+
else
|
120
|
+
path
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
# Holds source paths in instance so they can be manipulated.
|
125
|
+
#
|
126
|
+
def source_paths
|
127
|
+
@source_paths ||= self.class.source_paths_for_search
|
128
|
+
end
|
129
|
+
|
130
|
+
# Receives a file or directory and search for it in the source paths.
|
131
|
+
#
|
132
|
+
def find_in_source_paths(file) # rubocop:disable MethodLength
|
133
|
+
possible_files = [file, file + TEMPLATE_EXTNAME]
|
134
|
+
relative_root = relative_to_original_destination_root(destination_root, false)
|
135
|
+
|
136
|
+
source_paths.each do |source|
|
137
|
+
possible_files.each do |f|
|
138
|
+
source_file = File.expand_path(f, File.join(source, relative_root))
|
139
|
+
return source_file if File.exist?(source_file)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
message = "Could not find #{file.inspect} in any of your source paths. "
|
144
|
+
|
145
|
+
unless self.class.source_root
|
146
|
+
message << "Please invoke #{self.class.name}.source_root(PATH) with the PATH containing your templates. "
|
147
|
+
end
|
148
|
+
|
149
|
+
if source_paths.empty?
|
150
|
+
message << "Currently you have no source paths."
|
151
|
+
else
|
152
|
+
message << "Your current source paths are: \n#{source_paths.join("\n")}"
|
153
|
+
end
|
154
|
+
|
155
|
+
fail Error, message
|
156
|
+
end
|
157
|
+
|
158
|
+
# Do something in the root or on a provided subfolder. If a relative path
|
159
|
+
# is given it's referenced from the current root. The full path is yielded
|
160
|
+
# to the block you provide. The path is set back to the previous path when
|
161
|
+
# the method exits.
|
162
|
+
#
|
163
|
+
# ==== Parameters
|
164
|
+
# dir<String>:: the directory to move to.
|
165
|
+
# config<Hash>:: give :verbose => true to log and use padding.
|
166
|
+
#
|
167
|
+
def inside(dir = "", config = {}, &block)
|
168
|
+
verbose = config.fetch(:verbose, false)
|
169
|
+
pretend = options[:pretend]
|
170
|
+
|
171
|
+
say_status :inside, dir, verbose
|
172
|
+
shell.padding += 1 if verbose
|
173
|
+
@destination_stack.push File.expand_path(dir, destination_root)
|
174
|
+
|
175
|
+
# If the directory doesnt exist and we're not pretending
|
176
|
+
if !File.exist?(destination_root) && !pretend
|
177
|
+
FileUtils.mkdir_p(destination_root)
|
178
|
+
end
|
179
|
+
|
180
|
+
if pretend
|
181
|
+
# In pretend mode, just yield down to the block
|
182
|
+
block.arity == 1 ? yield(destination_root) : yield
|
183
|
+
else
|
184
|
+
FileUtils.cd(destination_root) { block.arity == 1 ? yield(destination_root) : yield }
|
185
|
+
end
|
186
|
+
|
187
|
+
@destination_stack.pop
|
188
|
+
shell.padding -= 1 if verbose
|
189
|
+
end
|
190
|
+
|
191
|
+
# Goes to the root and execute the given block.
|
192
|
+
#
|
193
|
+
def in_root
|
194
|
+
inside(@destination_stack.first) { yield }
|
195
|
+
end
|
196
|
+
|
197
|
+
# Loads an external file and execute it in the instance binding.
|
198
|
+
#
|
199
|
+
# ==== Parameters
|
200
|
+
# path<String>:: The path to the file to execute. Can be a web address or
|
201
|
+
# a relative path from the source root.
|
202
|
+
#
|
203
|
+
# ==== Examples
|
204
|
+
#
|
205
|
+
# apply "http://gist.github.com/103208"
|
206
|
+
#
|
207
|
+
# apply "recipes/jquery.rb"
|
208
|
+
#
|
209
|
+
def apply(path, config = {})
|
210
|
+
verbose = config.fetch(:verbose, true)
|
211
|
+
is_uri = path =~ %r{^https?\://}
|
212
|
+
path = find_in_source_paths(path) unless is_uri
|
213
|
+
|
214
|
+
say_status :apply, path, verbose
|
215
|
+
shell.padding += 1 if verbose
|
216
|
+
|
217
|
+
if is_uri
|
218
|
+
contents = open(path, "Accept" => "application/x-thor-template") { |io| io.read }
|
219
|
+
else
|
220
|
+
contents = open(path) { |io| io.read }
|
221
|
+
end
|
222
|
+
|
223
|
+
instance_eval(contents, path)
|
224
|
+
shell.padding -= 1 if verbose
|
225
|
+
end
|
226
|
+
|
227
|
+
# Executes a command returning the contents of the command.
|
228
|
+
#
|
229
|
+
# ==== Parameters
|
230
|
+
# command<String>:: the command to be executed.
|
231
|
+
# config<Hash>:: give :verbose => false to not log the status, :capture => true to hide to output. Specify :with
|
232
|
+
# to append an executable to command execution.
|
233
|
+
#
|
234
|
+
# ==== Example
|
235
|
+
#
|
236
|
+
# inside('vendor') do
|
237
|
+
# run('ln -s ~/edge rails')
|
238
|
+
# end
|
239
|
+
#
|
240
|
+
def run(command, config = {})
|
241
|
+
return unless behavior == :invoke
|
242
|
+
|
243
|
+
destination = relative_to_original_destination_root(destination_root, false)
|
244
|
+
desc = "#{command} from #{destination.inspect}"
|
245
|
+
|
246
|
+
if config[:with]
|
247
|
+
desc = "#{File.basename(config[:with].to_s)} #{desc}"
|
248
|
+
command = "#{config[:with]} #{command}"
|
249
|
+
end
|
250
|
+
|
251
|
+
say_status :run, desc, config.fetch(:verbose, true)
|
252
|
+
|
253
|
+
unless options[:pretend]
|
254
|
+
config[:capture] ? `#{command}` : system("#{command}")
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
# Executes a ruby script (taking into account WIN32 platform quirks).
|
259
|
+
#
|
260
|
+
# ==== Parameters
|
261
|
+
# command<String>:: the command to be executed.
|
262
|
+
# config<Hash>:: give :verbose => false to not log the status.
|
263
|
+
#
|
264
|
+
def run_ruby_script(command, config = {})
|
265
|
+
return unless behavior == :invoke
|
266
|
+
run command, config.merge(:with => Thor::Util.ruby_command)
|
267
|
+
end
|
268
|
+
|
269
|
+
# Run a thor command. A hash of options can be given and it's converted to
|
270
|
+
# switches.
|
271
|
+
#
|
272
|
+
# ==== Parameters
|
273
|
+
# command<String>:: the command to be invoked
|
274
|
+
# args<Array>:: arguments to the command
|
275
|
+
# config<Hash>:: give :verbose => false to not log the status, :capture => true to hide to output.
|
276
|
+
# Other options are given as parameter to Thor.
|
277
|
+
#
|
278
|
+
#
|
279
|
+
# ==== Examples
|
280
|
+
#
|
281
|
+
# thor :install, "http://gist.github.com/103208"
|
282
|
+
# #=> thor install http://gist.github.com/103208
|
283
|
+
#
|
284
|
+
# thor :list, :all => true, :substring => 'rails'
|
285
|
+
# #=> thor list --all --substring=rails
|
286
|
+
#
|
287
|
+
def thor(command, *args)
|
288
|
+
config = args.last.is_a?(Hash) ? args.pop : {}
|
289
|
+
verbose = config.key?(:verbose) ? config.delete(:verbose) : true
|
290
|
+
pretend = config.key?(:pretend) ? config.delete(:pretend) : false
|
291
|
+
capture = config.key?(:capture) ? config.delete(:capture) : false
|
292
|
+
|
293
|
+
args.unshift(command)
|
294
|
+
args.push Thor::Options.to_switches(config)
|
295
|
+
command = args.join(" ").strip
|
296
|
+
|
297
|
+
run command, :with => :thor, :verbose => verbose, :pretend => pretend, :capture => capture
|
298
|
+
end
|
299
|
+
|
300
|
+
protected
|
301
|
+
|
302
|
+
# Allow current root to be shared between invocations.
|
303
|
+
#
|
304
|
+
def _shared_configuration #:nodoc:
|
305
|
+
super.merge!(:destination_root => destination_root)
|
306
|
+
end
|
307
|
+
|
308
|
+
def _cleanup_options_and_set(options, key) #:nodoc:
|
309
|
+
case options
|
310
|
+
when Array
|
311
|
+
%w[--force -f --skip -s].each { |i| options.delete(i) }
|
312
|
+
options << "--#{key}"
|
313
|
+
when Hash
|
314
|
+
[:force, :skip, "force", "skip"].each { |i| options.delete(i) }
|
315
|
+
options.merge!(key => true)
|
316
|
+
end
|
317
|
+
end
|
318
|
+
end
|
319
|
+
end
|