| 
									
										
										
										
											2021-03-24 09:04:49 +01:00
										 |  |  | # typed: false | 
					
						
							|  |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class AbstractDownloadStrategy | 
					
						
							| 
									
										
										
										
											2021-04-03 20:10:25 +02:00
										 |  |  |   module CompatFetch | 
					
						
							| 
									
										
										
										
											2021-03-24 09:04:49 +01:00
										 |  |  |     def fetch(timeout: nil) | 
					
						
							|  |  |  |       super() | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-03 20:10:25 +02:00
										 |  |  |   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") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-09 14:12:40 +01:00
										 |  |  |         odeprecated "`def _fetch` in a subclass of `CurlDownloadStrategy`" | 
					
						
							| 
									
										
										
										
											2021-04-03 20:10:25 +02:00
										 |  |  |         options.delete(:timeout) | 
					
						
							|  |  |  |         super(*args, **options) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-24 09:04:49 +01:00
										 |  |  |   class << self | 
					
						
							|  |  |  |     def method_added(method) | 
					
						
							|  |  |  |       if method == :fetch && instance_method(method).arity.zero? | 
					
						
							| 
									
										
										
										
											2021-04-09 09:30:36 +01:00
										 |  |  |         odisabled "`def fetch` in a subclass of `#{self}`", | 
					
						
							|  |  |  |                   "`def fetch(timeout: nil, **options)` and output a warning " \ | 
					
						
							|  |  |  |                   "when `options` contains new unhandled options" | 
					
						
							| 
									
										
										
										
											2021-03-24 09:04:49 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         class_eval do | 
					
						
							| 
									
										
										
										
											2021-04-03 20:10:25 +02:00
										 |  |  |           prepend CompatFetch | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       elsif method == :_fetch | 
					
						
							|  |  |  |         class_eval do | 
					
						
							|  |  |  |           prepend Compat_Fetch | 
					
						
							| 
									
										
										
										
											2021-03-24 09:04:49 +01:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       super | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |