1# frozen_string_literal: true 2module Gem 3 DEFAULT_HOST = "https://rubygems.org".freeze 4 5 @post_install_hooks ||= [] 6 @done_installing_hooks ||= [] 7 @post_uninstall_hooks ||= [] 8 @pre_uninstall_hooks ||= [] 9 @pre_install_hooks ||= [] 10 11 ## 12 # An Array of the default sources that come with RubyGems 13 14 def self.default_sources 15 %w[https://rubygems.org/] 16 end 17 18 ## 19 # Default spec directory path to be used if an alternate value is not 20 # specified in the environment 21 22 def self.default_spec_cache_dir 23 File.join Gem.user_home, '.gem', 'specs' 24 end 25 26 ## 27 # Default home directory path to be used if an alternate value is not 28 # specified in the environment 29 30 def self.default_dir 31 path = if defined? RUBY_FRAMEWORK_VERSION 32 [ 33 File.dirname(RbConfig::CONFIG['sitedir']), 34 'Gems', 35 RbConfig::CONFIG['ruby_version'] 36 ] 37 elsif RbConfig::CONFIG['rubylibprefix'] 38 [ 39 RbConfig::CONFIG['rubylibprefix'], 40 'gems', 41 RbConfig::CONFIG['ruby_version'] 42 ] 43 else 44 [ 45 RbConfig::CONFIG['libdir'], 46 ruby_engine, 47 'gems', 48 RbConfig::CONFIG['ruby_version'] 49 ] 50 end 51 52 @default_dir ||= File.join(*path) 53 end 54 55 ## 56 # Returns binary extensions dir for specified RubyGems base dir or nil 57 # if such directory cannot be determined. 58 # 59 # By default, the binary extensions are located side by side with their 60 # Ruby counterparts, therefore nil is returned 61 62 def self.default_ext_dir_for(base_dir) 63 nil 64 end 65 66 ## 67 # Paths where RubyGems' .rb files and bin files are installed 68 69 def self.default_rubygems_dirs 70 nil # default to standard layout 71 end 72 73 ## 74 # Path for gems in the user's home directory 75 76 def self.user_dir 77 parts = [Gem.user_home, '.gem', ruby_engine] 78 parts << RbConfig::CONFIG['ruby_version'] unless RbConfig::CONFIG['ruby_version'].empty? 79 File.join parts 80 end 81 82 ## 83 # How String Gem paths should be split. Overridable for esoteric platforms. 84 85 def self.path_separator 86 File::PATH_SEPARATOR 87 end 88 89 ## 90 # Default gem load path 91 92 def self.default_path 93 path = [] 94 path << user_dir if user_home && File.exist?(user_home) 95 path << default_dir 96 path << vendor_dir if vendor_dir and File.directory? vendor_dir 97 path 98 end 99 100 ## 101 # Deduce Ruby's --program-prefix and --program-suffix from its install name 102 103 def self.default_exec_format 104 exec_format = RbConfig::CONFIG['ruby_install_name'].sub('ruby', '%s') rescue '%s' 105 106 unless exec_format =~ /%s/ 107 raise Gem::Exception, 108 "[BUG] invalid exec_format #{exec_format.inspect}, no %s" 109 end 110 111 exec_format 112 end 113 114 ## 115 # The default directory for binaries 116 117 def self.default_bindir 118 if defined? RUBY_FRAMEWORK_VERSION # mac framework support 119 '/usr/bin' 120 else # generic install 121 RbConfig::CONFIG['bindir'] 122 end 123 end 124 125 ## 126 # A wrapper around RUBY_ENGINE const that may not be defined 127 128 def self.ruby_engine 129 if defined? RUBY_ENGINE 130 RUBY_ENGINE 131 else 132 'ruby' 133 end 134 end 135 136 ## 137 # The default signing key path 138 139 def self.default_key_path 140 File.join Gem.user_home, ".gem", "gem-private_key.pem" 141 end 142 143 ## 144 # The default signing certificate chain path 145 146 def self.default_cert_path 147 File.join Gem.user_home, ".gem", "gem-public_cert.pem" 148 end 149 150 ## 151 # Whether to expect full paths in default gems - true for non-MRI 152 # ruby implementations 153 def self.default_gems_use_full_paths? 154 ruby_engine != 'ruby' 155 end 156 157 ## 158 # Install extensions into lib as well as into the extension directory. 159 160 def self.install_extension_in_lib # :nodoc: 161 true 162 end 163 164 ## 165 # Directory where vendor gems are installed. 166 167 def self.vendor_dir # :nodoc: 168 if vendor_dir = ENV['GEM_VENDOR'] 169 return vendor_dir.dup 170 end 171 172 return nil unless RbConfig::CONFIG.key? 'vendordir' 173 174 File.join RbConfig::CONFIG['vendordir'], 'gems', 175 RbConfig::CONFIG['ruby_version'] 176 end 177 178 ## 179 # Default options for gem commands for Ruby packagers. 180 # 181 # The options here should be structured as an array of string "gem" 182 # command names as keys and a string of the default options as values. 183 # 184 # Example: 185 # 186 # def self.operating_system_defaults 187 # { 188 # 'install' => '--no-rdoc --no-ri --env-shebang', 189 # 'update' => '--no-rdoc --no-ri --env-shebang' 190 # } 191 # end 192 193 def self.operating_system_defaults 194 {} 195 end 196 197 ## 198 # Default options for gem commands for Ruby implementers. 199 # 200 # The options here should be structured as an array of string "gem" 201 # command names as keys and a string of the default options as values. 202 # 203 # Example: 204 # 205 # def self.platform_defaults 206 # { 207 # 'install' => '--no-rdoc --no-ri --env-shebang', 208 # 'update' => '--no-rdoc --no-ri --env-shebang' 209 # } 210 # end 211 212 def self.platform_defaults 213 {} 214 end 215end 216