summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTanaka Akira <akr@fsij.org>2019-07-14 17:18:17 +0900
committerTanaka Akira <akr@fsij.org>2019-07-14 17:18:17 +0900
commit05aac90a1bcfeb180f5e78ea8b00a4d1b04d5eed (patch)
tree6d281c9ddb92f724fef239c57f38543604b875f9 /lib
parent9987296b8b5b7c02fca92761e498764dfeb584cf (diff)
Warn open-uri's "open" method at Kernel.
Use URI.open instead. Thanks for the patch by jeremyevans0 (Jeremy Evans) [Misc #15893].
Diffstat (limited to 'lib')
-rw-r--r--lib/open-uri.rb27
1 files changed, 18 insertions, 9 deletions
diff --git a/lib/open-uri.rb b/lib/open-uri.rb
index 38f074ef59..3aeed06ed4 100644
--- a/lib/open-uri.rb
+++ b/lib/open-uri.rb
@@ -10,6 +10,21 @@ module Kernel
alias open_uri_original_open open # :nodoc:
end
+ def open(name, *rest, &block) # :nodoc:
+ if (name.respond_to?(:open) && !name.respond_to?(:to_path)) ||
+ (name.respond_to?(:to_str) &&
+ %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://} =~ name &&
+ (uri = URI.parse(name)).respond_to?(:open))
+ warn('calling URI.open via Kernel#open is deprecated, call URI.open directly', uplevel: 1)
+ URI.open(name, *rest, &block)
+ else
+ open_uri_original_open(name, *rest, &block)
+ end
+ end
+ module_function :open
+end
+
+module URI
# Allows the opening of various resources including URIs.
#
# If the first argument responds to the 'open' method, 'open' is called on
@@ -26,7 +41,7 @@ module Kernel
#
# We can accept URIs and strings that begin with http://, https:// and
# ftp://. In these cases, the opened file object is extended by OpenURI::Meta.
- def open(name, *rest, &block) # :doc:
+ def self.open(name, *rest, &block)
if name.respond_to?(:open)
name.open(*rest, &block)
elsif name.respond_to?(:to_str) &&
@@ -35,16 +50,10 @@ module Kernel
uri.open(*rest, &block)
else
open_uri_original_open(name, *rest, &block)
+ # After Kernel#open override is removed:
+ #super
end
end
- module_function :open
-end
-
-module URI #:nodoc:
- # alias for Kernel.open defined in open-uri.
- def self.open(name, *rest, &block)
- Kernel.open(name, *rest, &block)
- end
end
# OpenURI is an easy-to-use wrapper for Net::HTTP, Net::HTTPS and Net::FTP.