diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-01-05 00:16:35 +0900 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2023-01-08 08:09:33 +0000 |
commit | 1a1b653c9c7f83599cb6df0c0d4f0332f466c5f6 (patch) | |
tree | 3f5985d5ab6f0e78c41013bff84a5abb42ba0ed9 /lib/rubygems/core_ext | |
parent | fd98169e00a050fab2e7f1a1cefcc92be4c8cb40 (diff) | |
download | ruby-1a1b653c9c7f83599cb6df0c0d4f0332f466c5f6.tar.gz |
[rubygems/rubygems] Let RDoc parse the doc of `Kernel#require`
Since RDoc does not parse string literals as documents, `eval` the
entire file instead of embedding in a here-document.
On the contrary, as `gem_original_require` alias is an implementation
detail but not for users, it should not be documented.
https://github.com/rubygems/rubygems/commit/cad4cf16cf
Diffstat (limited to 'lib/rubygems/core_ext')
-rw-r--r-- | lib/rubygems/core_ext/kernel_require.rb | 7 | ||||
-rw-r--r-- | lib/rubygems/core_ext/kernel_warn.rb | 69 |
2 files changed, 36 insertions, 40 deletions
diff --git a/lib/rubygems/core_ext/kernel_require.rb b/lib/rubygems/core_ext/kernel_require.rb index 8064d813e1..c53afe34d9 100644 --- a/lib/rubygems/core_ext/kernel_require.rb +++ b/lib/rubygems/core_ext/kernel_require.rb @@ -13,12 +13,12 @@ module Kernel # Make sure we have a reference to Ruby's original Kernel#require unless defined?(gem_original_require) + # :stopdoc: alias gem_original_require require private :gem_original_require + # :startdoc: end - file = Gem::KERNEL_WARN_IGNORES_INTERNAL_ENTRIES ? "<internal:#{__FILE__}>" : __FILE__ - module_eval <<'RUBY', file, __LINE__ + 1 # rubocop:disable Style/EvalWithLocation ## # When RubyGems is required, Kernel#require is replaced with our own which # is capable of loading gems on demand. @@ -33,7 +33,7 @@ module Kernel # The normal <tt>require</tt> functionality of returning false if # that file has already been loaded is preserved. - def require(path) + def require(path) # :doc: if RUBYGEMS_ACTIVATION_MONITOR.respond_to?(:mon_owned?) monitor_owned = RUBYGEMS_ACTIVATION_MONITOR.mon_owned? end @@ -168,7 +168,6 @@ module Kernel end end end -RUBY private :require diff --git a/lib/rubygems/core_ext/kernel_warn.rb b/lib/rubygems/core_ext/kernel_warn.rb index f0f173c0b1..1f4c77f04b 100644 --- a/lib/rubygems/core_ext/kernel_warn.rb +++ b/lib/rubygems/core_ext/kernel_warn.rb @@ -1,53 +1,50 @@ # frozen_string_literal: true -if !Gem::KERNEL_WARN_IGNORES_INTERNAL_ENTRIES +module Kernel + rubygems_path = "#{__dir__}/" # Frames to be skipped start with this path. - module Kernel - rubygems_path = "#{__dir__}/" # Frames to be skipped start with this path. + original_warn = instance_method(:warn) - original_warn = instance_method(:warn) + remove_method :warn + class << self remove_method :warn + end - class << self - remove_method :warn + module_function define_method(:warn) {|*messages, **kw| + unless uplevel = kw[:uplevel] + if Gem.java_platform? && RUBY_VERSION < "3.1" + return original_warn.bind(self).call(*messages) + else + return original_warn.bind(self).call(*messages, **kw) + end end - module_function define_method(:warn) {|*messages, **kw| - unless uplevel = kw[:uplevel] - if Gem.java_platform? && RUBY_VERSION < "3.1" - return original_warn.bind(self).call(*messages) - else - return original_warn.bind(self).call(*messages, **kw) + # Ensure `uplevel` fits a `long` + uplevel, = [uplevel].pack("l!").unpack("l!") + + if uplevel >= 0 + start = 0 + while uplevel >= 0 + loc, = caller_locations(start, 1) + unless loc + # No more backtrace + start += uplevel + break end - end - # Ensure `uplevel` fits a `long` - uplevel, = [uplevel].pack("l!").unpack("l!") - - if uplevel >= 0 - start = 0 - while uplevel >= 0 - loc, = caller_locations(start, 1) - unless loc - # No more backtrace - start += uplevel - break - end + start += 1 - start += 1 - - if path = loc.path - unless path.start_with?(rubygems_path) || path.start_with?("<internal:") - # Non-rubygems frames - uplevel -= 1 - end + if path = loc.path + unless path.start_with?(rubygems_path) || path.start_with?("<internal:") + # Non-rubygems frames + uplevel -= 1 end end - kw[:uplevel] = start end + kw[:uplevel] = start + end - original_warn.bind(self).call(*messages, **kw) - } - end + original_warn.bind(self).call(*messages, **kw) + } end |