[前][次][番号順一覧][スレッド一覧]

ruby-changes:60189

From: V=C3=ADt <ko1@a...>
Date: Wed, 26 Feb 2020 11:05:09 +0900 (JST)
Subject: [ruby-changes:60189] e960ef6f18 (master): Use `Gem::Package` like object instead of monkey patching.

https://git.ruby-lang.org/ruby.git/commit/?id=e960ef6f18

From e960ef6f18a25c637c54f00c75bb6c24f8ab55d0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?V=C3=ADt=20Ondruch?= <vondruch@r...>
Date: Tue, 1 Oct 2019 12:03:33 +0200
Subject: Use `Gem::Package` like object instead of monkey patching.

1. This is similar to what RubyGems does and it is less magic [[1]].
2. It avoids deprecated code paths in RubyGems [[2]].

[1]: https://github.com/rubygems/rubygems/blob/92892bbc3adba86a90756c385433835f6761b8da/lib/rubygems/installer.rb#L151
[2]: https://github.com/rubygems/rubygems/blob/92892bbc3adba86a90756c385433835f6761b8da/lib/rubygems/installer.rb#L187

diff --git a/tool/rbinstall.rb b/tool/rbinstall.rb
index a9b6b9b..7fc0109 100755
--- a/tool/rbinstall.rb
+++ b/tool/rbinstall.rb
@@ -706,29 +706,34 @@ module RbInstall https://github.com/ruby/ruby/blob/trunk/tool/rbinstall.rb#L706
     end
   end
 
-  class UnpackedInstaller < Gem::Installer
-    module DirPackage
-      def extract_files(destination_dir, pattern = "*")
-        path = File.dirname(@gem.path)
-        return if path == destination_dir
-        File.chmod(0700, destination_dir)
-        mode = pattern == "bin/*" ? $script_mode : $data_mode
-        spec.files.each do |f|
-          src = File.join(path, f)
-          dest = File.join(without_destdir(destination_dir), f)
-          makedirs(dest[/.*(?=\/)/m])
-          install src, dest, :mode => mode
-        end
-        File.chmod($dir_mode, destination_dir)
+  class DirPackage
+    attr_reader :spec
+
+    attr_accessor :dir_mode
+    attr_accessor :prog_mode
+    attr_accessor :data_mode
+
+    def initialize(spec)
+      @spec = spec
+      @src_dir = File.dirname(@spec.loaded_from)
+    end
+
+    def extract_files(destination_dir, pattern = "*")
+      path = @src_dir
+      return if path == destination_dir
+      File.chmod(0700, destination_dir)
+      mode = pattern == "bin/*" ? $script_mode : $data_mode
+      spec.files.each do |f|
+        src = File.join(path, f)
+        dest = File.join(without_destdir(destination_dir), f)
+        makedirs(dest[/.*(?=\/)/m])
+        install src, dest, :mode => mode
       end
+      File.chmod($dir_mode, destination_dir)
     end
+  end
 
-    def initialize(spec, *options)
-      package = Gem::Package.new(spec.loaded_from)
-      super(package, *options)
-      @package.extend(DirPackage).spec = spec
-    end
-
+  class UnpackedInstaller < Gem::Installer
     def write_cache_file
     end
 
@@ -890,7 +895,8 @@ install?(:ext, :comm, :gem, :'bundled-gems') do https://github.com/ruby/ruby/blob/trunk/tool/rbinstall.rb#L895
     if File.directory?(ext = "#{gem_ext_dir}/#{spec.full_name}")
       spec.extensions[0] ||= "-"
     end
-    ins = RbInstall::UnpackedInstaller.new(spec, options)
+    package = RbInstall::DirPackage.new spec
+    ins = RbInstall::UnpackedInstaller.new(package, options)
     puts "#{INDENT}#{spec.name} #{spec.version}"
     ins.install
     File.chmod($data_mode, File.join(install_dir, "specifications", "#{spec.full_name}.gemspec"))
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]