Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress URI.open warning in Ruby 2.7 #677

Merged
merged 1 commit into from
Sep 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/thor/actions/file_manipulation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ def get(source, *args, &block)
config = args.last.is_a?(Hash) ? args.pop : {}
destination = args.first

if source =~ %r{^https?\://}
render = if source =~ %r{^https?\://}
require "open-uri"
URI.send(:open, source) { |input| input.binmode.read }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need the send?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It uses send method because this is a private method in Ruby 2.4 and lower.

Ruby 2.5

% ruby -ropen-uri -ve 'URI.open("https://github.com/erikhuda/thor")'
ruby 2.5.6p201 (2019-08-28 revision 67796) [x86_64-darwin17]

Ruby 2.4

% ruby -ropen-uri -ve 'URI.open("https://github.com/erikhuda/thor")'
ruby 2.4.7p357 (2019-08-28 revision 67796) [x86_64-darwin17]
-e:1:in `<main>': private method `open' called for URI:Module (NoMethodError)

else
source = File.expand_path(find_in_source_paths(source.to_s))
open(source) { |input| input.binmode.read }
end

render = open(source) { |input| input.binmode.read }

destination ||= if block_given?
block.arity == 1 ? yield(render) : yield
else
Expand Down