290
290
module FileUtils
291
291
def unarchive ( archive )
292
292
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
294
294
elsif archive . downcase . end_with? ( '.zip' )
295
295
sh 'unzip' , '-o' , archive
296
296
else
@@ -299,37 +299,12 @@ module FileUtils
299
299
end
300
300
301
301
def fetch ( source_uri , dest_path = nil )
302
- require 'rubygems/remote_fetcher'
302
+ dest_path = File . basename ( source_uri ) if dest_path . nil?
303
303
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
330
305
331
306
unless Rake ::FileUtilsExt . nowrite_flag
332
- data = fetcher . public_send ( symbol , source_uri )
307
+ data = Utils . fetch_https ( source_uri )
333
308
Gem . write_binary ( dest_path , data )
334
309
end
335
310
@@ -574,8 +549,6 @@ module SassConfig
574
549
end
575
550
576
551
def protoc
577
- require 'rubygems/remote_fetcher'
578
-
579
552
repo = 'https://repo.maven.apache.org/maven2/com/google/protobuf/protoc'
580
553
581
554
dependency = Gem ::Dependency . new ( 'google-protobuf' )
@@ -614,7 +587,7 @@ module SassConfig
614
587
615
588
uri = "#{ repo } /#{ version } /protoc-#{ version } -#{ os } -#{ cpu } .exe"
616
589
617
- Gem :: RemoteFetcher . fetcher . fetch_https ( Gem :: Uri . new ( "#{ uri } .sha1" ) )
590
+ Utils . fetch_https ( "#{ uri } .sha1" )
618
591
619
592
uri
620
593
rescue Gem ::RemoteFetcher ::FetchError
@@ -627,7 +600,7 @@ module SassConfig
627
600
versions . sort . reverse_each do |v |
628
601
uri = "#{ repo } /#{ v } /protoc-#{ v } -#{ os } -#{ cpu } .exe"
629
602
630
- Gem :: RemoteFetcher . fetcher . fetch_https ( Gem :: Uri . new ( "#{ uri } .sha1" ) )
603
+ Utils . fetch_https ( "#{ uri } .sha1" )
631
604
632
605
return uri
633
606
rescue Gem ::RemoteFetcher ::FetchError
@@ -692,6 +665,23 @@ module SassConfig
692
665
platform
693
666
end
694
667
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
695
685
696
686
def windows_system_directory
697
687
require 'open3'
0 commit comments