Skip to content

Commit 862b302

Browse files
deivid-rodriguezhsbt
authored andcommitted
[rubygems/rubygems] Bump vendored thor to 1.4.0
ruby/rubygems@8078a747b3
1 parent 124cd77 commit 862b302

File tree

7 files changed

+52
-20
lines changed

7 files changed

+52
-20
lines changed

lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,35 @@ def inject_into_module(path, module_name, *args, &block)
242242
insert_into_file(path, *(args << config), &block)
243243
end
244244

245+
# Run a regular expression replacement on a file, raising an error if the
246+
# contents of the file are not changed.
247+
#
248+
# ==== Parameters
249+
# path<String>:: path of the file to be changed
250+
# flag<Regexp|String>:: the regexp or string to be replaced
251+
# replacement<String>:: the replacement, can be also given as a block
252+
# config<Hash>:: give :verbose => false to not log the status, and
253+
# :force => true, to force the replacement regardless of runner behavior.
254+
#
255+
# ==== Example
256+
#
257+
# gsub_file! 'app/controllers/application_controller.rb', /#\s*(filter_parameter_logging :password)/, '\1'
258+
#
259+
# gsub_file! 'README', /rake/, :green do |match|
260+
# match << " no more. Use thor!"
261+
# end
262+
#
263+
def gsub_file!(path, flag, *args, &block)
264+
config = args.last.is_a?(Hash) ? args.pop : {}
265+
266+
return unless behavior == :invoke || config.fetch(:force, false)
267+
268+
path = File.expand_path(path, destination_root)
269+
say_status :gsub, relative_to_original_destination_root(path), config.fetch(:verbose, true)
270+
271+
actually_gsub_file(path, flag, args, true, &block) unless options[:pretend]
272+
end
273+
245274
# Run a regular expression replacement on a file.
246275
#
247276
# ==== Parameters
@@ -267,11 +296,7 @@ def gsub_file(path, flag, *args, &block)
267296
path = File.expand_path(path, destination_root)
268297
say_status :gsub, relative_to_original_destination_root(path), config.fetch(:verbose, true)
269298

270-
unless options[:pretend]
271-
content = File.binread(path)
272-
content.gsub!(flag, *args, &block)
273-
File.open(path, "wb") { |file| file.write(content) }
274-
end
299+
actually_gsub_file(path, flag, args, false, &block) unless options[:pretend]
275300
end
276301

277302
# Uncomment all lines matching a given regex. Preserves indentation before
@@ -348,7 +373,7 @@ def capture(*args)
348373
end
349374

350375
def with_output_buffer(buf = "".dup) #:nodoc:
351-
raise ArgumentError, "Buffer can not be a frozen object" if buf.frozen?
376+
raise ArgumentError, "Buffer cannot be a frozen object" if buf.frozen?
352377
old_buffer = output_buffer
353378
self.output_buffer = buf
354379
yield
@@ -357,6 +382,17 @@ def with_output_buffer(buf = "".dup) #:nodoc:
357382
self.output_buffer = old_buffer
358383
end
359384

385+
def actually_gsub_file(path, flag, args, error_on_no_change, &block)
386+
content = File.binread(path)
387+
success = content.gsub!(flag, *args, &block)
388+
389+
if success.nil? && error_on_no_change
390+
raise Bundler::Thor::Error, "The content of #{path} did not change"
391+
end
392+
393+
File.open(path, "wb") { |file| file.write(content) }
394+
end
395+
360396
# Bundler::Thor::Actions#capture depends on what kind of buffer is used in ERB.
361397
# Thus CapturableERB fixes ERB to use String buffer.
362398
class CapturableERB < ERB

lib/bundler/vendor/thor/lib/thor/parser/options.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def parse(args) # rubocop:disable Metrics/MethodLength
144144
def check_exclusive!
145145
opts = @assigns.keys
146146
# When option A and B are exclusive, if A and B are given at the same time,
147-
# the diffrence of argument array size will decrease.
147+
# the difference of argument array size will decrease.
148148
found = @exclusives.find{ |ex| (ex - opts).size < ex.size - 1 }
149149
if found
150150
names = names_to_switch_names(found & opts).map{|n| "'#{n}'"}

lib/bundler/vendor/thor/lib/thor/runner.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
require_relative "../thor"
22
require_relative "group"
33

4-
require "yaml"
54
require "digest/sha2"
65
require "pathname"
76

@@ -195,6 +194,7 @@ def thor_root
195194
def thor_yaml
196195
@thor_yaml ||= begin
197196
yaml_file = File.join(thor_root, "thor.yml")
197+
require "yaml"
198198
yaml = YAML.load_file(yaml_file) if File.exist?(yaml_file)
199199
yaml || {}
200200
end

lib/bundler/vendor/thor/lib/thor/shell/basic.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def show_diff(destination, content) #:nodoc:
314314
diff_cmd = ENV["THOR_DIFF"] || ENV["RAILS_DIFF"] || "diff -u"
315315

316316
require "tempfile"
317-
Tempfile.open(File.basename(destination), File.dirname(destination)) do |temp|
317+
Tempfile.open(File.basename(destination), File.dirname(destination), binmode: true) do |temp|
318318
temp.write content
319319
temp.rewind
320320
system %(#{diff_cmd} "#{destination}" "#{temp.path}")
@@ -372,16 +372,12 @@ def merge(destination, content) #:nodoc:
372372
Tempfile.open([File.basename(destination), File.extname(destination)], File.dirname(destination)) do |temp|
373373
temp.write content
374374
temp.rewind
375-
system %(#{merge_tool} "#{temp.path}" "#{destination}")
375+
system(merge_tool, temp.path, destination)
376376
end
377377
end
378378

379379
def merge_tool #:nodoc:
380-
@merge_tool ||= ENV["THOR_MERGE"] || git_merge_tool
381-
end
382-
383-
def git_merge_tool #:nodoc:
384-
`git config merge.tool`.rstrip rescue ""
380+
@merge_tool ||= ENV["THOR_MERGE"] || "git difftool --no-index"
385381
end
386382
end
387383
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
class Bundler::Thor
2-
VERSION = "1.3.2"
2+
VERSION = "1.4.0"
33
end

tool/bundler/vendor_gems.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
gem "resolv", "0.6.2"
1313
gem "securerandom", "0.4.1"
1414
gem "timeout", "0.4.3"
15-
gem "thor", "1.3.2"
15+
gem "thor", "1.4.0"
1616
gem "tsort", "0.2.0"
1717
gem "uri", "1.0.3"

tool/bundler/vendor_gems.rb.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ GEM
3737
optparse (0.6.0)
3838
resolv (0.6.2)
3939
securerandom (0.4.1)
40-
thor (1.3.2)
40+
thor (1.4.0)
4141
timeout (0.4.3)
4242
tsort (0.2.0)
4343
uri (1.0.3)
@@ -60,7 +60,7 @@ DEPENDENCIES
6060
pub_grub!
6161
resolv (= 0.6.2)
6262
securerandom (= 0.4.1)
63-
thor (= 1.3.2)
63+
thor (= 1.4.0)
6464
timeout (= 0.4.3)
6565
tsort (= 0.2.0)
6666
uri (= 1.0.3)
@@ -76,7 +76,7 @@ CHECKSUMS
7676
pub_grub (0.5.0)
7777
resolv (0.6.2) sha256=61efe545cedddeb1b14f77e51f85c85ca66af5098fdbf567fadf32c34590fb14
7878
securerandom (0.4.1) sha256=cc5193d414a4341b6e225f0cb4446aceca8e50d5e1888743fac16987638ea0b1
79-
thor (1.3.2) sha256=eef0293b9e24158ccad7ab383ae83534b7ad4ed99c09f96f1a6b036550abbeda
79+
thor (1.4.0) sha256=8763e822ccb0f1d7bee88cde131b19a65606657b847cc7b7b4b82e772bcd8a3d
8080
timeout (0.4.3) sha256=9509f079b2b55fe4236d79633bd75e34c1c1e7e3fb4b56cb5fda61f80a0fe30e
8181
tsort (0.2.0) sha256=9650a793f6859a43b6641671278f79cfead60ac714148aabe4e3f0060480089f
8282
uri (1.0.3) sha256=e9f2244608eea2f7bc357d954c65c910ce0399ca5e18a7a29207ac22d8767011

0 commit comments

Comments
 (0)