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

ruby-changes:67463

From: Daniel <ko1@a...>
Date: Tue, 31 Aug 2021 19:07:39 +0900 (JST)
Subject: [ruby-changes:67463] f212b9d4f2 (master): [rubygems/rubygems] Refactor Ruby platform priority condition to its own method

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

From f212b9d4f2eb7f94359778d0ec5f3e38f2d90461 Mon Sep 17 00:00:00 2001
From: Daniel Niknam <mhmd.niknam@g...>
Date: Thu, 19 Aug 2021 21:57:57 +1000
Subject: [rubygems/rubygems] Refactor Ruby platform priority condition to its
 own method

The `Gem::Platform::RUBY ? -1 : 1` has been used multiple times in different places and could be refactored to a method (DRY).

https://github.com/rubygems/rubygems/commit/9d43ca8f0c
---
 lib/rubygems/name_tuple.rb             | 5 ++---
 lib/rubygems/platform.rb               | 4 ++++
 lib/rubygems/resolver/installer_set.rb | 2 +-
 lib/rubygems/specification.rb          | 4 ++--
 4 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/lib/rubygems/name_tuple.rb b/lib/rubygems/name_tuple.rb
index 3d0afa3..c732d7f 100644
--- a/lib/rubygems/name_tuple.rb
+++ b/lib/rubygems/name_tuple.rb
@@ -89,9 +89,8 @@ class Gem::NameTuple https://github.com/ruby/ruby/blob/trunk/lib/rubygems/name_tuple.rb#L89
   alias to_s inspect # :nodoc:
 
   def <=>(other)
-    [@name, @version, @platform == Gem::Platform::RUBY ? -1 : 1] <=>
-      [other.name, other.version,
-       other.platform == Gem::Platform::RUBY ? -1 : 1]
+    [@name, @version, Gem::Platform.sort_priority(@platform)] <=>
+      [other.name, other.version, Gem::Platform.sort_priority(other.platform)]
   end
 
   include Comparable
diff --git a/lib/rubygems/platform.rb b/lib/rubygems/platform.rb
index 9750df1..4b8ac31 100644
--- a/lib/rubygems/platform.rb
+++ b/lib/rubygems/platform.rb
@@ -40,6 +40,10 @@ class Gem::Platform https://github.com/ruby/ruby/blob/trunk/lib/rubygems/platform.rb#L40
     match_platforms?(platform, Gem.platforms)
   end
 
+  def self.sort_priority(platform)
+    platform == Gem::Platform::RUBY ? -1 : 1
+  end
+
   def self.installable?(spec)
     if spec.respond_to? :installable_platform?
       spec.installable_platform?
diff --git a/lib/rubygems/resolver/installer_set.rb b/lib/rubygems/resolver/installer_set.rb
index f4fee35..237bc3f 100644
--- a/lib/rubygems/resolver/installer_set.rb
+++ b/lib/rubygems/resolver/installer_set.rb
@@ -71,7 +71,7 @@ class Gem::Resolver::InstallerSet < Gem::Resolver::Set https://github.com/ruby/ruby/blob/trunk/lib/rubygems/resolver/installer_set.rb#L71
     end
 
     found = found.sort_by do |s|
-      [s.version, s.platform == Gem::Platform::RUBY ? -1 : 1]
+      [s.version, Gem::Platform.sort_priority(s.platform)]
     end
 
     newest = found.last
diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb
index 83277fd..7ed9634 100644
--- a/lib/rubygems/specification.rb
+++ b/lib/rubygems/specification.rb
@@ -855,7 +855,7 @@ class Gem::Specification < Gem::BasicSpecification https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification.rb#L855
       next names if names.nonzero?
       versions = b.version <=> a.version
       next versions if versions.nonzero?
-      b.platform == Gem::Platform::RUBY ? -1 : 1
+      Gem::Platform.sort_priority(b.platform)
     end
   end
 
@@ -2333,7 +2333,7 @@ class Gem::Specification < Gem::BasicSpecification https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification.rb#L2333
   # Returns an object you can use to sort specifications in #sort_by.
 
   def sort_obj
-    [@name, @version, @new_platform == Gem::Platform::RUBY ? -1 : 1]
+    [@name, @version, Gem::Platform.sort_priority(@new_platform)]
   end
 
   ##
-- 
cgit v1.1


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

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