290290module FileUtils
291291 def unarchive ( archive )
292292 if Gem . win_platform?
293- sh File . absolute_path ( 'tar.exe' , SassConfig . windows_system_directory ) , '-vxf' , archive
293+ sh File . absolute_path ( 'tar.exe' , Utils . windows_system_directory ) , '-vxf' , archive
294294 elsif archive . downcase . end_with? ( '.zip' )
295295 sh 'unzip' , '-o' , archive
296296 else
@@ -299,37 +299,12 @@ module FileUtils
299299 end
300300
301301 def fetch ( source_uri , dest_path = nil )
302- require 'rubygems/remote_fetcher'
302+ dest_path = File . basename ( source_uri ) if dest_path . nil?
303303
304- source_uri = "/#{ source_uri } " if !source_uri . start_with? ( '/' ) && File . absolute_path? ( source_uri )
305-
306- source_uri = begin
307- Gem ::Uri . parse! ( source_uri )
308- rescue NoMethodError
309- begin
310- URI . parse ( source_uri )
311- rescue StandardError
312- URI . parse ( URI ::DEFAULT_PARSER . escape ( source_uri . to_s ) )
313- end
314- end
315-
316- scheme = source_uri . scheme
317- source_path = begin
318- Gem ::URI ::DEFAULT_PARSER
319- rescue NameError
320- URI ::DEFAULT_PARSER
321- end . unescape ( source_uri . path )
322-
323- dest_path = File . basename ( source_path ) if dest_path . nil?
324-
325- fetcher = Gem ::RemoteFetcher . fetcher
326- symbol = :"fetch_#{ scheme . nil? ? 'file' : scheme } "
327- raise ArgumentError , "Unsupported URI scheme #{ scheme } " unless fetcher . respond_to? ( symbol )
328-
329- Rake . rake_output_message "fetch #{ Gem ::Uri . new ( source_uri ) . redacted } " if Rake ::FileUtilsExt . verbose_flag
304+ Rake . rake_output_message "fetch #{ source_uri } " if Rake ::FileUtilsExt . verbose_flag
330305
331306 unless Rake ::FileUtilsExt . nowrite_flag
332- data = fetcher . public_send ( symbol , source_uri )
307+ data = Utils . fetch_https ( source_uri )
333308 Gem . write_binary ( dest_path , data )
334309 end
335310
@@ -574,8 +549,6 @@ module SassConfig
574549 end
575550
576551 def protoc
577- require 'rubygems/remote_fetcher'
578-
579552 repo = 'https://repo.maven.apache.org/maven2/com/google/protobuf/protoc'
580553
581554 dependency = Gem ::Dependency . new ( 'google-protobuf' )
@@ -614,7 +587,7 @@ module SassConfig
614587
615588 uri = "#{ repo } /#{ version } /protoc-#{ version } -#{ os } -#{ cpu } .exe"
616589
617- Gem :: RemoteFetcher . fetcher . fetch_https ( Gem :: Uri . new ( "#{ uri } .sha1" ) )
590+ Utils . fetch_https ( "#{ uri } .sha1" )
618591
619592 uri
620593 rescue Gem ::RemoteFetcher ::FetchError
@@ -627,7 +600,7 @@ module SassConfig
627600 versions . sort . reverse_each do |v |
628601 uri = "#{ repo } /#{ v } /protoc-#{ v } -#{ os } -#{ cpu } .exe"
629602
630- Gem :: RemoteFetcher . fetcher . fetch_https ( Gem :: Uri . new ( "#{ uri } .sha1" ) )
603+ Utils . fetch_https ( "#{ uri } .sha1" )
631604
632605 return uri
633606 rescue Gem ::RemoteFetcher ::FetchError
@@ -692,6 +665,23 @@ module SassConfig
692665 platform
693666 end
694667 end
668+ end
669+
670+ # The {Utils} module.
671+ module Utils
672+ module_function
673+
674+ def fetch_https ( source_uri )
675+ require 'rubygems/remote_fetcher'
676+
677+ source_uri = begin
678+ Gem ::Uri . parse! ( source_uri )
679+ rescue NoMethodError
680+ URI . parse ( source_uri )
681+ end
682+
683+ Gem ::RemoteFetcher . fetcher . fetch_https ( source_uri )
684+ end
695685
696686 def windows_system_directory
697687 require 'open3'
0 commit comments