honeybadger 5.0.2 → 5.1.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 +713 -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 +51 -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 +413 -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/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 +51 -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 +11 -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 +10 -5
@@ -1,103 +1,103 @@
|
|
1
|
-
require "thor/actions/empty_directory"
|
2
|
-
|
3
|
-
class Thor
|
4
|
-
module Actions
|
5
|
-
# Create a new file relative to the destination root with the given data,
|
6
|
-
# which is the return value of a block or a data string.
|
7
|
-
#
|
8
|
-
# ==== Parameters
|
9
|
-
# destination<String>:: the relative path to the destination root.
|
10
|
-
# data<String|NilClass>:: the data to append to the file.
|
11
|
-
# config<Hash>:: give :verbose => false to not log the status.
|
12
|
-
#
|
13
|
-
# ==== Examples
|
14
|
-
#
|
15
|
-
# create_file "lib/fun_party.rb" do
|
16
|
-
# hostname = ask("What is the virtual hostname I should use?")
|
17
|
-
# "vhost.name = #{hostname}"
|
18
|
-
# end
|
19
|
-
#
|
20
|
-
# create_file "config/apache.conf", "your apache config"
|
21
|
-
#
|
22
|
-
def create_file(destination, *args, &block)
|
23
|
-
config = args.last.is_a?(Hash) ? args.pop : {}
|
24
|
-
data = args.first
|
25
|
-
action CreateFile.new(self, destination, block || data.to_s, config)
|
26
|
-
end
|
27
|
-
alias_method :add_file, :create_file
|
28
|
-
|
29
|
-
# CreateFile is a subset of Template, which instead of rendering a file with
|
30
|
-
# ERB, it gets the content from the user.
|
31
|
-
#
|
32
|
-
class CreateFile < EmptyDirectory #:nodoc:
|
33
|
-
attr_reader :data
|
34
|
-
|
35
|
-
def initialize(base, destination, data, config = {})
|
36
|
-
@data = data
|
37
|
-
super(base, destination, config)
|
38
|
-
end
|
39
|
-
|
40
|
-
# Checks if the content of the file at the destination is identical to the rendered result.
|
41
|
-
#
|
42
|
-
# ==== Returns
|
43
|
-
# Boolean:: true if it is identical, false otherwise.
|
44
|
-
#
|
45
|
-
def identical?
|
46
|
-
exists? && File.binread(destination) == render
|
47
|
-
end
|
48
|
-
|
49
|
-
# Holds the content to be added to the file.
|
50
|
-
#
|
51
|
-
def render
|
52
|
-
@render ||= if data.is_a?(Proc)
|
53
|
-
data.call
|
54
|
-
else
|
55
|
-
data
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def invoke!
|
60
|
-
invoke_with_conflict_check do
|
61
|
-
FileUtils.mkdir_p(File.dirname(destination))
|
62
|
-
File.open(destination, "wb") { |f| f.write render }
|
63
|
-
end
|
64
|
-
given_destination
|
65
|
-
end
|
66
|
-
|
67
|
-
protected
|
68
|
-
|
69
|
-
# Now on conflict we check if the file is identical or not.
|
70
|
-
#
|
71
|
-
def on_conflict_behavior(&block)
|
72
|
-
if identical?
|
73
|
-
say_status :identical, :blue
|
74
|
-
else
|
75
|
-
options = base.options.merge(config)
|
76
|
-
force_or_skip_or_conflict(options[:force], options[:skip], &block)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
# If force is true, run the action, otherwise check if it's not being
|
81
|
-
# skipped. If both are false, show the file_collision menu, if the menu
|
82
|
-
# returns true, force it, otherwise skip.
|
83
|
-
#
|
84
|
-
def force_or_skip_or_conflict(force, skip, &block)
|
85
|
-
if force
|
86
|
-
say_status :force, :yellow
|
87
|
-
block.call unless pretend?
|
88
|
-
elsif skip
|
89
|
-
say_status :skip, :yellow
|
90
|
-
else
|
91
|
-
say_status :conflict, :red
|
92
|
-
force_or_skip_or_conflict(force_on_collision?, true, &block)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
# Shows the file collision menu to the user and gets the result.
|
97
|
-
#
|
98
|
-
def force_on_collision?
|
99
|
-
base.shell.file_collision(destination) { render }
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
1
|
+
require "thor/actions/empty_directory"
|
2
|
+
|
3
|
+
class Thor
|
4
|
+
module Actions
|
5
|
+
# Create a new file relative to the destination root with the given data,
|
6
|
+
# which is the return value of a block or a data string.
|
7
|
+
#
|
8
|
+
# ==== Parameters
|
9
|
+
# destination<String>:: the relative path to the destination root.
|
10
|
+
# data<String|NilClass>:: the data to append to the file.
|
11
|
+
# config<Hash>:: give :verbose => false to not log the status.
|
12
|
+
#
|
13
|
+
# ==== Examples
|
14
|
+
#
|
15
|
+
# create_file "lib/fun_party.rb" do
|
16
|
+
# hostname = ask("What is the virtual hostname I should use?")
|
17
|
+
# "vhost.name = #{hostname}"
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# create_file "config/apache.conf", "your apache config"
|
21
|
+
#
|
22
|
+
def create_file(destination, *args, &block)
|
23
|
+
config = args.last.is_a?(Hash) ? args.pop : {}
|
24
|
+
data = args.first
|
25
|
+
action CreateFile.new(self, destination, block || data.to_s, config)
|
26
|
+
end
|
27
|
+
alias_method :add_file, :create_file
|
28
|
+
|
29
|
+
# CreateFile is a subset of Template, which instead of rendering a file with
|
30
|
+
# ERB, it gets the content from the user.
|
31
|
+
#
|
32
|
+
class CreateFile < EmptyDirectory #:nodoc:
|
33
|
+
attr_reader :data
|
34
|
+
|
35
|
+
def initialize(base, destination, data, config = {})
|
36
|
+
@data = data
|
37
|
+
super(base, destination, config)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Checks if the content of the file at the destination is identical to the rendered result.
|
41
|
+
#
|
42
|
+
# ==== Returns
|
43
|
+
# Boolean:: true if it is identical, false otherwise.
|
44
|
+
#
|
45
|
+
def identical?
|
46
|
+
exists? && File.binread(destination) == render
|
47
|
+
end
|
48
|
+
|
49
|
+
# Holds the content to be added to the file.
|
50
|
+
#
|
51
|
+
def render
|
52
|
+
@render ||= if data.is_a?(Proc)
|
53
|
+
data.call
|
54
|
+
else
|
55
|
+
data
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def invoke!
|
60
|
+
invoke_with_conflict_check do
|
61
|
+
FileUtils.mkdir_p(File.dirname(destination))
|
62
|
+
File.open(destination, "wb") { |f| f.write render }
|
63
|
+
end
|
64
|
+
given_destination
|
65
|
+
end
|
66
|
+
|
67
|
+
protected
|
68
|
+
|
69
|
+
# Now on conflict we check if the file is identical or not.
|
70
|
+
#
|
71
|
+
def on_conflict_behavior(&block)
|
72
|
+
if identical?
|
73
|
+
say_status :identical, :blue
|
74
|
+
else
|
75
|
+
options = base.options.merge(config)
|
76
|
+
force_or_skip_or_conflict(options[:force], options[:skip], &block)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# If force is true, run the action, otherwise check if it's not being
|
81
|
+
# skipped. If both are false, show the file_collision menu, if the menu
|
82
|
+
# returns true, force it, otherwise skip.
|
83
|
+
#
|
84
|
+
def force_or_skip_or_conflict(force, skip, &block)
|
85
|
+
if force
|
86
|
+
say_status :force, :yellow
|
87
|
+
block.call unless pretend?
|
88
|
+
elsif skip
|
89
|
+
say_status :skip, :yellow
|
90
|
+
else
|
91
|
+
say_status :conflict, :red
|
92
|
+
force_or_skip_or_conflict(force_on_collision?, true, &block)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# Shows the file collision menu to the user and gets the result.
|
97
|
+
#
|
98
|
+
def force_on_collision?
|
99
|
+
base.shell.file_collision(destination) { render }
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -1,59 +1,59 @@
|
|
1
|
-
require "thor/actions/create_file"
|
2
|
-
|
3
|
-
class Thor
|
4
|
-
module Actions
|
5
|
-
# Create a new file relative to the destination root from the given source.
|
6
|
-
#
|
7
|
-
# ==== Parameters
|
8
|
-
# destination<String>:: the relative path to the destination root.
|
9
|
-
# source<String|NilClass>:: the relative path to the source root.
|
10
|
-
# config<Hash>:: give :verbose => false to not log the status.
|
11
|
-
# :: give :symbolic => false for hard link.
|
12
|
-
#
|
13
|
-
# ==== Examples
|
14
|
-
#
|
15
|
-
# create_link "config/apache.conf", "/etc/apache.conf"
|
16
|
-
#
|
17
|
-
def create_link(destination, *args, &block)
|
18
|
-
config = args.last.is_a?(Hash) ? args.pop : {}
|
19
|
-
source = args.first
|
20
|
-
action CreateLink.new(self, destination, source, config)
|
21
|
-
end
|
22
|
-
alias_method :add_link, :create_link
|
23
|
-
|
24
|
-
# CreateLink is a subset of CreateFile, which instead of taking a block of
|
25
|
-
# data, just takes a source string from the user.
|
26
|
-
#
|
27
|
-
class CreateLink < CreateFile #:nodoc:
|
28
|
-
attr_reader :data
|
29
|
-
|
30
|
-
# Checks if the content of the file at the destination is identical to the rendered result.
|
31
|
-
#
|
32
|
-
# ==== Returns
|
33
|
-
# Boolean:: true if it is identical, false otherwise.
|
34
|
-
#
|
35
|
-
def identical?
|
36
|
-
exists? && File.identical?(render, destination)
|
37
|
-
end
|
38
|
-
|
39
|
-
def invoke!
|
40
|
-
invoke_with_conflict_check do
|
41
|
-
FileUtils.mkdir_p(File.dirname(destination))
|
42
|
-
# Create a symlink by default
|
43
|
-
config[:symbolic] = true if config[:symbolic].nil?
|
44
|
-
File.unlink(destination) if exists?
|
45
|
-
if config[:symbolic]
|
46
|
-
File.symlink(render, destination)
|
47
|
-
else
|
48
|
-
File.link(render, destination)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
given_destination
|
52
|
-
end
|
53
|
-
|
54
|
-
def exists?
|
55
|
-
super || File.symlink?(destination)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
1
|
+
require "thor/actions/create_file"
|
2
|
+
|
3
|
+
class Thor
|
4
|
+
module Actions
|
5
|
+
# Create a new file relative to the destination root from the given source.
|
6
|
+
#
|
7
|
+
# ==== Parameters
|
8
|
+
# destination<String>:: the relative path to the destination root.
|
9
|
+
# source<String|NilClass>:: the relative path to the source root.
|
10
|
+
# config<Hash>:: give :verbose => false to not log the status.
|
11
|
+
# :: give :symbolic => false for hard link.
|
12
|
+
#
|
13
|
+
# ==== Examples
|
14
|
+
#
|
15
|
+
# create_link "config/apache.conf", "/etc/apache.conf"
|
16
|
+
#
|
17
|
+
def create_link(destination, *args, &block)
|
18
|
+
config = args.last.is_a?(Hash) ? args.pop : {}
|
19
|
+
source = args.first
|
20
|
+
action CreateLink.new(self, destination, source, config)
|
21
|
+
end
|
22
|
+
alias_method :add_link, :create_link
|
23
|
+
|
24
|
+
# CreateLink is a subset of CreateFile, which instead of taking a block of
|
25
|
+
# data, just takes a source string from the user.
|
26
|
+
#
|
27
|
+
class CreateLink < CreateFile #:nodoc:
|
28
|
+
attr_reader :data
|
29
|
+
|
30
|
+
# Checks if the content of the file at the destination is identical to the rendered result.
|
31
|
+
#
|
32
|
+
# ==== Returns
|
33
|
+
# Boolean:: true if it is identical, false otherwise.
|
34
|
+
#
|
35
|
+
def identical?
|
36
|
+
exists? && File.identical?(render, destination)
|
37
|
+
end
|
38
|
+
|
39
|
+
def invoke!
|
40
|
+
invoke_with_conflict_check do
|
41
|
+
FileUtils.mkdir_p(File.dirname(destination))
|
42
|
+
# Create a symlink by default
|
43
|
+
config[:symbolic] = true if config[:symbolic].nil?
|
44
|
+
File.unlink(destination) if exists?
|
45
|
+
if config[:symbolic]
|
46
|
+
File.symlink(render, destination)
|
47
|
+
else
|
48
|
+
File.link(render, destination)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
given_destination
|
52
|
+
end
|
53
|
+
|
54
|
+
def exists?
|
55
|
+
super || File.symlink?(destination)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -1,118 +1,118 @@
|
|
1
|
-
require "thor/actions/empty_directory"
|
2
|
-
|
3
|
-
class Thor
|
4
|
-
module Actions
|
5
|
-
# Copies recursively the files from source directory to root directory.
|
6
|
-
# If any of the files finishes with .tt, it's considered to be a template
|
7
|
-
# and is placed in the destination without the extension .tt. If any
|
8
|
-
# empty directory is found, it's copied and all .empty_directory files are
|
9
|
-
# ignored. If any file name is wrapped within % signs, the text within
|
10
|
-
# the % signs will be executed as a method and replaced with the returned
|
11
|
-
# value. Let's suppose a doc directory with the following files:
|
12
|
-
#
|
13
|
-
# doc/
|
14
|
-
# components/.empty_directory
|
15
|
-
# README
|
16
|
-
# rdoc.rb.tt
|
17
|
-
# %app_name%.rb
|
18
|
-
#
|
19
|
-
# When invoked as:
|
20
|
-
#
|
21
|
-
# directory "doc"
|
22
|
-
#
|
23
|
-
# It will create a doc directory in the destination with the following
|
24
|
-
# files (assuming that the `app_name` method returns the value "blog"):
|
25
|
-
#
|
26
|
-
# doc/
|
27
|
-
# components/
|
28
|
-
# README
|
29
|
-
# rdoc.rb
|
30
|
-
# blog.rb
|
31
|
-
#
|
32
|
-
# <b>Encoded path note:</b> Since Thor internals use Object#respond_to? to check if it can
|
33
|
-
# expand %something%, this `something` should be a public method in the class calling
|
34
|
-
# #directory. If a method is private, Thor stack raises PrivateMethodEncodedError.
|
35
|
-
#
|
36
|
-
# ==== Parameters
|
37
|
-
# source<String>:: the relative path to the source root.
|
38
|
-
# destination<String>:: the relative path to the destination root.
|
39
|
-
# config<Hash>:: give :verbose => false to not log the status.
|
40
|
-
# If :recursive => false, does not look for paths recursively.
|
41
|
-
# If :mode => :preserve, preserve the file mode from the source.
|
42
|
-
# If :exclude_pattern => /regexp/, prevents copying files that match that regexp.
|
43
|
-
#
|
44
|
-
# ==== Examples
|
45
|
-
#
|
46
|
-
# directory "doc"
|
47
|
-
# directory "doc", "docs", :recursive => false
|
48
|
-
#
|
49
|
-
def directory(source, *args, &block)
|
50
|
-
config = args.last.is_a?(Hash) ? args.pop : {}
|
51
|
-
destination = args.first || source
|
52
|
-
action Directory.new(self, source, destination || source, config, &block)
|
53
|
-
end
|
54
|
-
|
55
|
-
class Directory < EmptyDirectory #:nodoc:
|
56
|
-
attr_reader :source
|
57
|
-
|
58
|
-
def initialize(base, source, destination = nil, config = {}, &block)
|
59
|
-
@source = File.expand_path(base.find_in_source_paths(source.to_s))
|
60
|
-
@block = block
|
61
|
-
super(base, destination, {:recursive => true}.merge(config))
|
62
|
-
end
|
63
|
-
|
64
|
-
def invoke!
|
65
|
-
base.empty_directory given_destination, config
|
66
|
-
execute!
|
67
|
-
end
|
68
|
-
|
69
|
-
def revoke!
|
70
|
-
execute!
|
71
|
-
end
|
72
|
-
|
73
|
-
protected
|
74
|
-
|
75
|
-
def execute! # rubocop:disable MethodLength
|
76
|
-
lookup = Util.escape_globs(source)
|
77
|
-
lookup = config[:recursive] ? File.join(lookup, "**") : lookup
|
78
|
-
lookup = file_level_lookup(lookup)
|
79
|
-
|
80
|
-
files(lookup).sort.each do |file_source|
|
81
|
-
next if File.directory?(file_source)
|
82
|
-
next if config[:exclude_pattern] && file_source.match(config[:exclude_pattern])
|
83
|
-
file_destination = File.join(given_destination, file_source.gsub(source, "."))
|
84
|
-
file_destination.gsub!("/./", "/")
|
85
|
-
|
86
|
-
case file_source
|
87
|
-
when /\.empty_directory$/
|
88
|
-
dirname = File.dirname(file_destination).gsub(/\/\.$/, "")
|
89
|
-
next if dirname == given_destination
|
90
|
-
base.empty_directory(dirname, config)
|
91
|
-
when /#{TEMPLATE_EXTNAME}$/
|
92
|
-
base.template(file_source, file_destination[0..-4], config, &@block)
|
93
|
-
else
|
94
|
-
base.copy_file(file_source, file_destination, config, &@block)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
if RUBY_VERSION < "2.0"
|
100
|
-
def file_level_lookup(previous_lookup)
|
101
|
-
File.join(previous_lookup, "{*,.[a-z]*}")
|
102
|
-
end
|
103
|
-
|
104
|
-
def files(lookup)
|
105
|
-
Dir[lookup]
|
106
|
-
end
|
107
|
-
else
|
108
|
-
def file_level_lookup(previous_lookup)
|
109
|
-
File.join(previous_lookup, "*")
|
110
|
-
end
|
111
|
-
|
112
|
-
def files(lookup)
|
113
|
-
Dir.glob(lookup, File::FNM_DOTMATCH)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
1
|
+
require "thor/actions/empty_directory"
|
2
|
+
|
3
|
+
class Thor
|
4
|
+
module Actions
|
5
|
+
# Copies recursively the files from source directory to root directory.
|
6
|
+
# If any of the files finishes with .tt, it's considered to be a template
|
7
|
+
# and is placed in the destination without the extension .tt. If any
|
8
|
+
# empty directory is found, it's copied and all .empty_directory files are
|
9
|
+
# ignored. If any file name is wrapped within % signs, the text within
|
10
|
+
# the % signs will be executed as a method and replaced with the returned
|
11
|
+
# value. Let's suppose a doc directory with the following files:
|
12
|
+
#
|
13
|
+
# doc/
|
14
|
+
# components/.empty_directory
|
15
|
+
# README
|
16
|
+
# rdoc.rb.tt
|
17
|
+
# %app_name%.rb
|
18
|
+
#
|
19
|
+
# When invoked as:
|
20
|
+
#
|
21
|
+
# directory "doc"
|
22
|
+
#
|
23
|
+
# It will create a doc directory in the destination with the following
|
24
|
+
# files (assuming that the `app_name` method returns the value "blog"):
|
25
|
+
#
|
26
|
+
# doc/
|
27
|
+
# components/
|
28
|
+
# README
|
29
|
+
# rdoc.rb
|
30
|
+
# blog.rb
|
31
|
+
#
|
32
|
+
# <b>Encoded path note:</b> Since Thor internals use Object#respond_to? to check if it can
|
33
|
+
# expand %something%, this `something` should be a public method in the class calling
|
34
|
+
# #directory. If a method is private, Thor stack raises PrivateMethodEncodedError.
|
35
|
+
#
|
36
|
+
# ==== Parameters
|
37
|
+
# source<String>:: the relative path to the source root.
|
38
|
+
# destination<String>:: the relative path to the destination root.
|
39
|
+
# config<Hash>:: give :verbose => false to not log the status.
|
40
|
+
# If :recursive => false, does not look for paths recursively.
|
41
|
+
# If :mode => :preserve, preserve the file mode from the source.
|
42
|
+
# If :exclude_pattern => /regexp/, prevents copying files that match that regexp.
|
43
|
+
#
|
44
|
+
# ==== Examples
|
45
|
+
#
|
46
|
+
# directory "doc"
|
47
|
+
# directory "doc", "docs", :recursive => false
|
48
|
+
#
|
49
|
+
def directory(source, *args, &block)
|
50
|
+
config = args.last.is_a?(Hash) ? args.pop : {}
|
51
|
+
destination = args.first || source
|
52
|
+
action Directory.new(self, source, destination || source, config, &block)
|
53
|
+
end
|
54
|
+
|
55
|
+
class Directory < EmptyDirectory #:nodoc:
|
56
|
+
attr_reader :source
|
57
|
+
|
58
|
+
def initialize(base, source, destination = nil, config = {}, &block)
|
59
|
+
@source = File.expand_path(base.find_in_source_paths(source.to_s))
|
60
|
+
@block = block
|
61
|
+
super(base, destination, {:recursive => true}.merge(config))
|
62
|
+
end
|
63
|
+
|
64
|
+
def invoke!
|
65
|
+
base.empty_directory given_destination, config
|
66
|
+
execute!
|
67
|
+
end
|
68
|
+
|
69
|
+
def revoke!
|
70
|
+
execute!
|
71
|
+
end
|
72
|
+
|
73
|
+
protected
|
74
|
+
|
75
|
+
def execute! # rubocop:disable MethodLength
|
76
|
+
lookup = Util.escape_globs(source)
|
77
|
+
lookup = config[:recursive] ? File.join(lookup, "**") : lookup
|
78
|
+
lookup = file_level_lookup(lookup)
|
79
|
+
|
80
|
+
files(lookup).sort.each do |file_source|
|
81
|
+
next if File.directory?(file_source)
|
82
|
+
next if config[:exclude_pattern] && file_source.match(config[:exclude_pattern])
|
83
|
+
file_destination = File.join(given_destination, file_source.gsub(source, "."))
|
84
|
+
file_destination.gsub!("/./", "/")
|
85
|
+
|
86
|
+
case file_source
|
87
|
+
when /\.empty_directory$/
|
88
|
+
dirname = File.dirname(file_destination).gsub(/\/\.$/, "")
|
89
|
+
next if dirname == given_destination
|
90
|
+
base.empty_directory(dirname, config)
|
91
|
+
when /#{TEMPLATE_EXTNAME}$/
|
92
|
+
base.template(file_source, file_destination[0..-4], config, &@block)
|
93
|
+
else
|
94
|
+
base.copy_file(file_source, file_destination, config, &@block)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
if RUBY_VERSION < "2.0"
|
100
|
+
def file_level_lookup(previous_lookup)
|
101
|
+
File.join(previous_lookup, "{*,.[a-z]*}")
|
102
|
+
end
|
103
|
+
|
104
|
+
def files(lookup)
|
105
|
+
Dir[lookup]
|
106
|
+
end
|
107
|
+
else
|
108
|
+
def file_level_lookup(previous_lookup)
|
109
|
+
File.join(previous_lookup, "*")
|
110
|
+
end
|
111
|
+
|
112
|
+
def files(lookup)
|
113
|
+
Dir.glob(lookup, File::FNM_DOTMATCH)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|