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

Fix warnings caused by Ruby 2.7 update #530

Merged
merged 7 commits into from
Jul 31, 2020
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
language: ruby
rvm:
- 2.3
- 2.4
- 2.5
- 2.6
- 2.7
- ruby-head
- jruby-9.1.6.0
env:
Expand Down
2 changes: 1 addition & 1 deletion lib/roo/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ def download_uri(uri, tmpdir)
tempfilename = File.join(tmpdir, find_basename(uri))
begin
File.open(tempfilename, "wb") do |file|
open(uri, "User-Agent" => "Ruby/#{RUBY_VERSION}") do |net|
URI.open(uri, "User-Agent" => "Ruby/#{RUBY_VERSION}") do |net|
file.write(net.read)
end
end
Expand Down
14 changes: 10 additions & 4 deletions lib/roo/csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,23 @@ def read_cells(sheet = default_sheet)
def each_row(options, &block)
if uri?(filename)
each_row_using_tempdir(options, &block)
elsif is_stream?(filename_or_stream)
::CSV.new(filename_or_stream, options).each(&block)
else
::CSV.foreach(filename, options, &block)
csv_foreach(filename_or_stream, options, &block)
end
end

def each_row_using_tempdir(options, &block)
::Dir.mktmpdir(Roo::TEMP_PREFIX, ENV["ROO_TMP"]) do |tmpdir|
tmp_filename = download_uri(filename, tmpdir)
::CSV.foreach(tmp_filename, options, &block)
csv_foreach(tmp_filename, options, &block)
end
end

def csv_foreach(path_or_io, options, &block)
if is_stream?(path_or_io)
::CSV.new(path_or_io, **options).each(&block)
else
::CSV.foreach(path_or_io, **options, &block)
end
end

Expand Down
10 changes: 8 additions & 2 deletions lib/roo/spreadsheet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@ def extension_for(path, options)
options[:file_warning] = :ignore
extension.tr('.', '').downcase.to_sym
else
res = ::File.extname((path =~ /\A#{::URI::DEFAULT_PARSER.make_regexp}\z/) ? ::URI.parse(::URI.encode(path)).path : path)
res.tr('.', '').downcase.to_sym
parsed_path =
if path =~ /\A#{::URI::DEFAULT_PARSER.make_regexp}\z/
# path is 7th match
Regexp.last_match[7]
else
path
end
::File.extname(parsed_path).tr('.', '').downcase.to_sym
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions roo.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ Gem::Specification.new do |spec|
spec.files.reject! { |fn| fn.include?('test/files') }
spec.require_paths = ['lib']

spec.required_ruby_version = ">= 2.3.0"
spec.required_ruby_version = ">= 2.5.0"

spec.add_dependency 'nokogiri', '~> 1'
spec.add_dependency 'rubyzip', '>= 1.3.0', '< 3.0.0'

spec.add_development_dependency 'rake', '~> 10.1'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'minitest', '~> 5.4', '>= 5.4.3'
spec.add_development_dependency 'rack', '~> 1.6', '< 2.0.0'
end