Improve _fetch compatibility layer.

This commit is contained in:
Markus Reiter 2021-04-03 20:10:25 +02:00
parent 06a5811b4b
commit ab04cfed83
No known key found for this signature in database
GPG Key ID: 245293B51702655B
3 changed files with 23 additions and 25 deletions

View File

@ -2,21 +2,41 @@
# frozen_string_literal: true
class AbstractDownloadStrategy
module Compat
module CompatFetch
def fetch(timeout: nil)
super()
end
end
module Compat_Fetch # rubocop:disable Naming/ClassAndModuleCamelCase
def _fetch(*args, **options)
options[:timeout] = nil unless options.key?(:timeout)
begin
super
rescue ArgumentError => e
raise unless e.message.include?("timeout")
odeprecated "`def _fetch` in a subclass of `CurlDownloadStrategy`"
options.delete(:timeout)
super(*args, **options)
end
end
end
class << self
def method_added(method)
if method == :fetch && instance_method(method).arity.zero?
odeprecated "`def fetch` in a subclass of #{self}",
odeprecated "`def fetch` in a subclass of `#{self}`",
"`def fetch(timeout: nil, **options)` and output a warning " \
"when `options` contains new unhandled options"
class_eval do
prepend Compat
prepend CompatFetch
end
elsif method == :_fetch
class_eval do
prepend Compat_Fetch
end
end

View File

@ -1,4 +1,2 @@
# typed: strict
# frozen_string_literal: true
require_relative "late/download_strategy"

View File

@ -1,20 +0,0 @@
# typed: false
# frozen_string_literal: true
class CurlDownloadStrategy
module Compat
def _fetch(*args, **options)
unless options.key?(:timeout)
odeprecated "#{self.class}#_fetch"
options[:timeout] = nil
end
super(*args, **options)
end
end
prepend Compat
end
class CurlPostDownloadStrategy
prepend Compat
end