class Gem::DependencyInstaller
从本地和远程 gem 安装 gem 及其所有依赖项。
属性
文档类型。供 Gem.done_installing hook 使用
在搜索远程规范时来自 SpecFetcher 的错误
由 install 安装的 gem 列表,按字母顺序排列
Public Class Methods
Source
# File lib/rubygems/dependency_installer.rb, line 65 def initialize(options = {}) @only_install_dir = !options[:install_dir].nil? @install_dir = options[:install_dir] || Gem.dir @build_root = options[:build_root] options = DEFAULT_OPTIONS.merge options @bin_dir = options[:bin_dir] @dev_shallow = options[:dev_shallow] @development = options[:development] @document = options[:document] @domain = options[:domain] @env_shebang = options[:env_shebang] @force = options[:force] @format_executable = options[:format_executable] @ignore_dependencies = options[:ignore_dependencies] @prerelease = options[:prerelease] @security_policy = options[:security_policy] @user_install = options[:user_install] @wrappers = options[:wrappers] @build_args = options[:build_args] @build_jobs = options[:build_jobs] @build_docs_in_background = options[:build_docs_in_background] @dir_mode = options[:dir_mode] @data_mode = options[:data_mode] @prog_mode = options[:prog_mode] # Indicates that we should not try to update any deps unless # we absolutely must. @minimal_deps = options[:minimal_deps] @available = nil @installed_gems = [] @toplevel_specs = nil @cache_dir = options[:cache_dir] || @install_dir @errors = [] end
创建一个新的安装程序实例。
选项包括
- :cache_dir
-
用于存储 .gem 文件的备用存储库路径。
- :domain
-
:local, :remote, 或 :both。:local 仅搜索当前目录中的 gem。:remote 仅搜索
Gem::sources中的 gem。:both 搜索两者。 - :env_shebang
-
请参阅
Gem::Installer::new。 - :force
- :format_executable
-
请参阅 Gem::Installer#initialize。
- :ignore_dependencies
-
不安装任何依赖项。
- :install_dir
- :prerelease
-
允许预发布版本。请参阅
install。 - :security_policy
-
请参阅
Gem::Installer::new和Gem::Security。 - :user_install
- :wrappers
- :build_args
Public Instance Methods
Source
# File lib/rubygems/dependency_installer.rb, line 109 def consider_local? @domain == :both || @domain == :local end
根据请求的域,指示是否应考虑本地 gem。
Source
# File lib/rubygems/dependency_installer.rb, line 117 def consider_remote? @domain == :both || @domain == :remote end
根据请求的域,指示是否应考虑远程 gem。
Source
# File lib/rubygems/dependency_installer.rb, line 150 def install(dep_or_name, version = Gem::Requirement.default) request_set = resolve_dependencies dep_or_name, version @installed_gems = [] options = { bin_dir: @bin_dir, build_args: @build_args, build_jobs: @build_jobs, document: @document, env_shebang: @env_shebang, force: @force, format_executable: @format_executable, ignore_dependencies: @ignore_dependencies, prerelease: @prerelease, security_policy: @security_policy, user_install: @user_install, wrappers: @wrappers, build_root: @build_root, dir_mode: @dir_mode, data_mode: @data_mode, prog_mode: @prog_mode, } options[:install_dir] = @install_dir if @only_install_dir request_set.install options do |_, installer| @installed_gems << installer.spec if installer end @installed_gems.sort! # Since this is currently only called for docs, we can be lazy and just say # it's documentation. Ideally the hook adder could decide whether to be in # the background or not, and what to call it. in_background "Installing documentation" do Gem.done_installing_hooks.each do |hook| hook.call self, @installed_gems end end unless Gem.done_installing_hooks.empty? @installed_gems end
安装 gem dep_or_name 及其所有依赖项。返回一个已安装 gem 规范的 Array。
如果设置了 :prerelease 选项,并且 dep_or_name 有预发布版本,则将安装该预发布版本。
除非明确指定为预发布依赖项,否则 dep_or_name 所依赖的预发布 gem 将不会被安装。
如果 c-1.a 依赖于 b-1 且有 gem a-1.a 和 b-1.a 可用,则将安装 c-1.a、b-1 和 a-1.a。b-1.a 需要单独安装。