summaryrefslogtreecommitdiff
path: root/lib/open-uri.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/open-uri.rb')
-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.