f8d165
From 60eb961c25f801ee43ca1be9393ab2f0a0546677 Mon Sep 17 00:00:00 2001
f8d165
From: =?UTF-8?q?V=C3=ADt=20Ondruch?= <vondruch@redhat.com>
f8d165
Date: Tue, 19 Dec 2017 14:00:20 +0100
f8d165
Subject: [PATCH] Add Gem.operating_system_defaults to allow packagers to
f8d165
 override defaults.
f8d165
f8d165
This change allows Ruby packagers to override defaults and lazily query
f8d165
them.
f8d165
f8d165
This is very much the same change as #1644 to treat the
f8d165
operating_system defaults the same way as platform defaults.
f8d165
---
f8d165
 lib/rubygems/config_file.rb |  2 +-
f8d165
 lib/rubygems/defaults.rb    | 21 ++++++++++++++++++++-
f8d165
 test/rubygems/test_gem.rb   |  7 +++++++
f8d165
 3 files changed, 28 insertions(+), 2 deletions(-)
f8d165
f8d165
diff --git a/lib/rubygems/config_file.rb b/lib/rubygems/config_file.rb
f8d165
index a4efed0f5a..deee38e6d9 100644
f8d165
--- a/lib/rubygems/config_file.rb
f8d165
+++ b/lib/rubygems/config_file.rb
f8d165
@@ -48,7 +48,7 @@ class Gem::ConfigFile
f8d165
   # For Ruby packagers to set configuration defaults.  Set in
f8d165
   # rubygems/defaults/operating_system.rb
f8d165
 
f8d165
-  OPERATING_SYSTEM_DEFAULTS = {}
f8d165
+  OPERATING_SYSTEM_DEFAULTS = Gem.operating_system_defaults
f8d165
 
f8d165
   ##
f8d165
   # For Ruby implementers to set configuration defaults.  Set in
f8d165
diff --git a/lib/rubygems/defaults.rb b/lib/rubygems/defaults.rb
f8d165
index 43d57fc808..b8222877ae 100644
f8d165
--- a/lib/rubygems/defaults.rb
f8d165
+++ b/lib/rubygems/defaults.rb
f8d165
@@ -177,7 +177,26 @@ def self.vendor_dir # :nodoc:
f8d165
   end
f8d165
 
f8d165
   ##
f8d165
-  # Default options for gem commands.
f8d165
+  # Default options for gem commands for Ruby packagers.
f8d165
+  #
f8d165
+  # The options here should be structured as an array of string "gem"
f8d165
+  # command names as keys and a string of the default options as values.
f8d165
+  #
f8d165
+  # Example:
f8d165
+  #
f8d165
+  # def self.operating_system_defaults
f8d165
+  #   {
f8d165
+  #       'install' => '--no-rdoc --no-ri --env-shebang',
f8d165
+  #       'update' => '--no-rdoc --no-ri --env-shebang'
f8d165
+  #   }
f8d165
+  # end
f8d165
+
f8d165
+  def self.operating_system_defaults
f8d165
+    {}
f8d165
+  end
f8d165
+
f8d165
+  ##
f8d165
+  # Default options for gem commands for Ruby implementers.
f8d165
   #
f8d165
   # The options here should be structured as an array of string "gem"
f8d165
   # command names as keys and a string of the default options as values.
f8d165
diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb
f8d165
index 3225a05c6b..62b80c4945 100644
f8d165
--- a/test/rubygems/test_gem.rb
f8d165
+++ b/test/rubygems/test_gem.rb
f8d165
@@ -1837,6 +1837,13 @@ def test_use_gemdeps_specific
f8d165
     ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
f8d165
   end
f8d165
 
f8d165
+  def test_operating_system_defaults
f8d165
+    operating_system_defaults = Gem.operating_system_defaults
f8d165
+
f8d165
+    assert operating_system_defaults != nil
f8d165
+    assert operating_system_defaults.is_a? Hash
f8d165
+  end
f8d165
+
f8d165
   def test_platform_defaults
f8d165
     platform_defaults = Gem.platform_defaults
f8d165