From fe7d134b2fe2b3f2fa7381d55a94bb04803cbbb9 Mon Sep 17 00:00:00 2001 From: taichi Date: Fri, 10 Jan 2020 14:47:33 +0900 Subject: [PATCH 1/7] added Ruby 2.7 to CI --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 4dc862bd..2b77f209 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ rvm: - 2.4 - 2.5 - 2.6 + - 2.7 - ruby-head - jruby-9.1.6.0 env: From 1f9213cbdef667202f310fe6238195f23eed1654 Mon Sep 17 00:00:00 2001 From: taichi Date: Fri, 10 Jan 2020 14:58:34 +0900 Subject: [PATCH 2/7] removed version specification of 'rake' gem --- roo.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roo.gemspec b/roo.gemspec index 814c5fcd..dd4bf901 100644 --- a/roo.gemspec +++ b/roo.gemspec @@ -22,7 +22,7 @@ Gem::Specification.new do |spec| 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 From 22d99302b34c5a38acfc2806daaf94a449f1e821 Mon Sep 17 00:00:00 2001 From: taichi Date: Fri, 10 Jan 2020 15:23:24 +0900 Subject: [PATCH 3/7] fixed warnings caused by keyword argument change see: https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/ --- lib/roo/csv.rb | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/roo/csv.rb b/lib/roo/csv.rb index 516def6a..cc25b6cc 100644 --- a/lib/roo/csv.rb +++ b/lib/roo/csv.rb @@ -90,17 +90,36 @@ 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 + + # From Ruby 2.5, options argument of CSV.new/CSV.foreach is a keyword argument. + # Before Ruby 2.5, that argument is a Hash. + # Therefore, this workaround can be removed if Ruby 2.3 and 2.4 are dropped. + if RUBY_VERSION >= '2.5.0' + 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 + else + 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 end From 7b14229c1c519bddb50d5b359bbe8a35adaf402e Mon Sep 17 00:00:00 2001 From: taichi Date: Fri, 10 Jan 2020 16:41:36 +0900 Subject: [PATCH 4/7] adapted for deprecation of Kernel#open re-defined by 'open-uri' see: https://github.com/ruby/ruby/blob/v2_7_0/NEWS --- lib/roo/base.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/roo/base.rb b/lib/roo/base.rb index 19eb844b..aa72ef03 100644 --- a/lib/roo/base.rb +++ b/lib/roo/base.rb @@ -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| + open_uri(uri, "User-Agent" => "Ruby/#{RUBY_VERSION}") do |net| file.write(net.read) end end @@ -554,6 +554,18 @@ def download_uri(uri, tmpdir) tempfilename end + # Kernel#open re-defined by 'open-uri' is deprecated from Ruby 2.7. + # Before Ruby 2.5, URI.open is not defined by 'open-uri'. + # Therefore, this workaround is needed. + def open_uri(uri, options, &block) + require "open-uri" + if RUBY_VERSION >= '2.5.0' + URI.open(uri, options, &block) + else + open(uri, options, &block) + end + end + def open_from_stream(stream, tmpdir) tempfilename = File.join(tmpdir, "spreadsheet") File.open(tempfilename, "wb") do |file| From 9e1e002f3a6f303fa17647b4456f95f29e273d2a Mon Sep 17 00:00:00 2001 From: taichi Date: Fri, 10 Jan 2020 17:12:31 +0900 Subject: [PATCH 5/7] adapted for obsoletion of URI.encode method --- lib/roo/spreadsheet.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/roo/spreadsheet.rb b/lib/roo/spreadsheet.rb index cdc93f03..54063b67 100644 --- a/lib/roo/spreadsheet.rb +++ b/lib/roo/spreadsheet.rb @@ -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 From 1a4ec560babffd6083627e023fa520e1f775392a Mon Sep 17 00:00:00 2001 From: Taichi Ishitani Date: Tue, 28 Jul 2020 23:56:52 +0900 Subject: [PATCH 6/7] removed workaround for Ruby 2.3 & 2.4 --- lib/roo/base.rb | 14 +------------- lib/roo/csv.rb | 23 +++++------------------ 2 files changed, 6 insertions(+), 31 deletions(-) diff --git a/lib/roo/base.rb b/lib/roo/base.rb index aa72ef03..f4ac9a3c 100644 --- a/lib/roo/base.rb +++ b/lib/roo/base.rb @@ -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(uri, "User-Agent" => "Ruby/#{RUBY_VERSION}") do |net| + URI.open(uri, "User-Agent" => "Ruby/#{RUBY_VERSION}") do |net| file.write(net.read) end end @@ -554,18 +554,6 @@ def download_uri(uri, tmpdir) tempfilename end - # Kernel#open re-defined by 'open-uri' is deprecated from Ruby 2.7. - # Before Ruby 2.5, URI.open is not defined by 'open-uri'. - # Therefore, this workaround is needed. - def open_uri(uri, options, &block) - require "open-uri" - if RUBY_VERSION >= '2.5.0' - URI.open(uri, options, &block) - else - open(uri, options, &block) - end - end - def open_from_stream(stream, tmpdir) tempfilename = File.join(tmpdir, "spreadsheet") File.open(tempfilename, "wb") do |file| diff --git a/lib/roo/csv.rb b/lib/roo/csv.rb index cc25b6cc..4431bc20 100644 --- a/lib/roo/csv.rb +++ b/lib/roo/csv.rb @@ -102,24 +102,11 @@ def each_row_using_tempdir(options, &block) end end - # From Ruby 2.5, options argument of CSV.new/CSV.foreach is a keyword argument. - # Before Ruby 2.5, that argument is a Hash. - # Therefore, this workaround can be removed if Ruby 2.3 and 2.4 are dropped. - if RUBY_VERSION >= '2.5.0' - 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 - else - 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 + 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 From 4b995de947e702f673db8fa0c583d56c31b773d5 Mon Sep 17 00:00:00 2001 From: Taichi Ishitani Date: Tue, 28 Jul 2020 23:58:57 +0900 Subject: [PATCH 7/7] drop Ruby 2.3 & 2.4 support --- .travis.yml | 2 -- roo.gemspec | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2b77f209..4045e955 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,5 @@ language: ruby rvm: - - 2.3 - - 2.4 - 2.5 - 2.6 - 2.7 diff --git a/roo.gemspec b/roo.gemspec index dd4bf901..cc30a7a7 100644 --- a/roo.gemspec +++ b/roo.gemspec @@ -17,7 +17,7 @@ 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'