[rubygems/rubygems] Bump vendored thor to 1.4.0

8078a747b3
This commit is contained in:
David Rodríguez 2025-07-25 11:51:41 +02:00 committed by Hiroshi SHIBATA
parent 124cd77470
commit 862b30287a
7 changed files with 52 additions and 20 deletions

View file

@ -242,6 +242,35 @@ class Bundler::Thor
insert_into_file(path, *(args << config), &block)
end
# Run a regular expression replacement on a file, raising an error if the
# contents of the file are not changed.
#
# ==== Parameters
# path<String>:: path of the file to be changed
# flag<Regexp|String>:: the regexp or string to be replaced
# replacement<String>:: the replacement, can be also given as a block
# config<Hash>:: give :verbose => false to not log the status, and
# :force => true, to force the replacement regardless of runner behavior.
#
# ==== Example
#
# gsub_file! 'app/controllers/application_controller.rb', /#\s*(filter_parameter_logging :password)/, '\1'
#
# gsub_file! 'README', /rake/, :green do |match|
# match << " no more. Use thor!"
# end
#
def gsub_file!(path, flag, *args, &block)
config = args.last.is_a?(Hash) ? args.pop : {}
return unless behavior == :invoke || config.fetch(:force, false)
path = File.expand_path(path, destination_root)
say_status :gsub, relative_to_original_destination_root(path), config.fetch(:verbose, true)
actually_gsub_file(path, flag, args, true, &block) unless options[:pretend]
end
# Run a regular expression replacement on a file.
#
# ==== Parameters
@ -267,11 +296,7 @@ class Bundler::Thor
path = File.expand_path(path, destination_root)
say_status :gsub, relative_to_original_destination_root(path), config.fetch(:verbose, true)
unless options[:pretend]
content = File.binread(path)
content.gsub!(flag, *args, &block)
File.open(path, "wb") { |file| file.write(content) }
end
actually_gsub_file(path, flag, args, false, &block) unless options[:pretend]
end
# Uncomment all lines matching a given regex. Preserves indentation before
@ -348,7 +373,7 @@ class Bundler::Thor
end
def with_output_buffer(buf = "".dup) #:nodoc:
raise ArgumentError, "Buffer can not be a frozen object" if buf.frozen?
raise ArgumentError, "Buffer cannot be a frozen object" if buf.frozen?
old_buffer = output_buffer
self.output_buffer = buf
yield
@ -357,6 +382,17 @@ class Bundler::Thor
self.output_buffer = old_buffer
end
def actually_gsub_file(path, flag, args, error_on_no_change, &block)
content = File.binread(path)
success = content.gsub!(flag, *args, &block)
if success.nil? && error_on_no_change
raise Bundler::Thor::Error, "The content of #{path} did not change"
end
File.open(path, "wb") { |file| file.write(content) }
end
# Bundler::Thor::Actions#capture depends on what kind of buffer is used in ERB.
# Thus CapturableERB fixes ERB to use String buffer.
class CapturableERB < ERB

View file

@ -144,7 +144,7 @@ class Bundler::Thor
def check_exclusive!
opts = @assigns.keys
# When option A and B are exclusive, if A and B are given at the same time,
# the diffrence of argument array size will decrease.
# the difference of argument array size will decrease.
found = @exclusives.find{ |ex| (ex - opts).size < ex.size - 1 }
if found
names = names_to_switch_names(found & opts).map{|n| "'#{n}'"}

View file

@ -1,7 +1,6 @@
require_relative "../thor"
require_relative "group"
require "yaml"
require "digest/sha2"
require "pathname"
@ -195,6 +194,7 @@ private
def thor_yaml
@thor_yaml ||= begin
yaml_file = File.join(thor_root, "thor.yml")
require "yaml"
yaml = YAML.load_file(yaml_file) if File.exist?(yaml_file)
yaml || {}
end

View file

@ -314,7 +314,7 @@ class Bundler::Thor
diff_cmd = ENV["THOR_DIFF"] || ENV["RAILS_DIFF"] || "diff -u"
require "tempfile"
Tempfile.open(File.basename(destination), File.dirname(destination)) do |temp|
Tempfile.open(File.basename(destination), File.dirname(destination), binmode: true) do |temp|
temp.write content
temp.rewind
system %(#{diff_cmd} "#{destination}" "#{temp.path}")
@ -372,16 +372,12 @@ class Bundler::Thor
Tempfile.open([File.basename(destination), File.extname(destination)], File.dirname(destination)) do |temp|
temp.write content
temp.rewind
system %(#{merge_tool} "#{temp.path}" "#{destination}")
system(merge_tool, temp.path, destination)
end
end
def merge_tool #:nodoc:
@merge_tool ||= ENV["THOR_MERGE"] || git_merge_tool
end
def git_merge_tool #:nodoc:
`git config merge.tool`.rstrip rescue ""
@merge_tool ||= ENV["THOR_MERGE"] || "git difftool --no-index"
end
end
end

View file

@ -1,3 +1,3 @@
class Bundler::Thor
VERSION = "1.3.2"
VERSION = "1.4.0"
end

View file

@ -12,6 +12,6 @@ gem "pub_grub", github: "jhawthorn/pub_grub", ref: "df6add45d1b4d122daff2f959c9b
gem "resolv", "0.6.2"
gem "securerandom", "0.4.1"
gem "timeout", "0.4.3"
gem "thor", "1.3.2"
gem "thor", "1.4.0"
gem "tsort", "0.2.0"
gem "uri", "1.0.3"

View file

@ -37,7 +37,7 @@ GEM
optparse (0.6.0)
resolv (0.6.2)
securerandom (0.4.1)
thor (1.3.2)
thor (1.4.0)
timeout (0.4.3)
tsort (0.2.0)
uri (1.0.3)
@ -60,7 +60,7 @@ DEPENDENCIES
pub_grub!
resolv (= 0.6.2)
securerandom (= 0.4.1)
thor (= 1.3.2)
thor (= 1.4.0)
timeout (= 0.4.3)
tsort (= 0.2.0)
uri (= 1.0.3)
@ -76,7 +76,7 @@ CHECKSUMS
pub_grub (0.5.0)
resolv (0.6.2) sha256=61efe545cedddeb1b14f77e51f85c85ca66af5098fdbf567fadf32c34590fb14
securerandom (0.4.1) sha256=cc5193d414a4341b6e225f0cb4446aceca8e50d5e1888743fac16987638ea0b1
thor (1.3.2) sha256=eef0293b9e24158ccad7ab383ae83534b7ad4ed99c09f96f1a6b036550abbeda
thor (1.4.0) sha256=8763e822ccb0f1d7bee88cde131b19a65606657b847cc7b7b4b82e772bcd8a3d
timeout (0.4.3) sha256=9509f079b2b55fe4236d79633bd75e34c1c1e7e3fb4b56cb5fda61f80a0fe30e
tsort (0.2.0) sha256=9650a793f6859a43b6641671278f79cfead60ac714148aabe4e3f0060480089f
uri (1.0.3) sha256=e9f2244608eea2f7bc357d954c65c910ce0399ca5e18a7a29207ac22d8767011