class Gem::DependencyInstaller
从本地和远程 gem 安装 gem 及其所有依赖项。
属性
document[R]
文档类型。供 Gem.done_installing
钩子使用
errors[R]
在搜索远程规范时,来自 SpecFetcher 的错误
installed_gems[R]
install
安装的 gem 的字母顺序列表
公共类方法
new(options = {}) 点击切换源代码
创建新的安装程序实例。
选项包括
- :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
# File rubygems/dependency_installer.rb, line 68 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_docs_in_background = options[:build_docs_in_background] @install_as_default = options[:install_as_default] @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
公共实例方法
consider_local?() 点击切换源代码
根据请求的域指示是否应考虑本地 gem。
# File rubygems/dependency_installer.rb, line 112 def consider_local? @domain == :both || @domain == :local end
consider_remote?() 点击切换源代码
根据请求的域指示是否应考虑远程 gem。
# File rubygems/dependency_installer.rb, line 120 def consider_remote? @domain == :both || @domain == :remote end
install(dep_or_name, version = Gem::Requirement.default) 点击切换源代码
安装 gem dep_or_name
及其所有依赖项。返回已安装的 gem 规范的数组。
如果设置了 :prerelease
选项,并且 dep_or_name
有预发布版本,则将安装预发布版本。
除非明确指定为预发布依赖项,否则 dep_or_name
依赖的预发布 gem 将不会被安装。
如果 c-1.a 依赖于 b-1 和 a-1.a,并且有 gem b-1.a 可用,则将安装 c-1.a、b-1 和 a-1.a。 b-1.a 需要单独安装。
# File rubygems/dependency_installer.rb, line 225 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, 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, install_as_default: @install_as_default, 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