class Bundler::LazySpecification
属性
dependencies[RW]
force_ruby_platform[RW]
materialization[R]
most_specific_locked_platform[RW]
为了与现有的 lockfile 保持向后兼容,如果最具体的锁定平台不是像 x86_64-linux 或 universal-java-11 这样的特定平台,那么我们将保持在物化时解析最佳平台变体的先前行为。对于之前的 bundler 版本(2.2.0 之前),情况总是如此(除非 lockfile 仅包含非 ruby 平台),但我们也将在较新的 bundler 上保留此行为,除非用户从头开始生成 lockfile 或显式添加更具体的平台。
name[R]
platform[R]
remote[RW]
required_ruby_version[RW]
required_rubygems_version[RW]
runtime_dependencies[RW]
source[RW]
version[R]
公共类方法
from_spec(s) 点击以切换源代码
# File bundler/lazy_specification.rb, line 28 def self.from_spec(s) lazy_spec = new(s.name, s.version, s.platform, s.source) lazy_spec.dependencies = s.runtime_dependencies lazy_spec.required_ruby_version = s.required_ruby_version lazy_spec.required_rubygems_version = s.required_rubygems_version lazy_spec end
new(name, version, platform, source = nil) 点击以切换源代码
# File bundler/lazy_specification.rb, line 36 def initialize(name, version, platform, source = nil) @name = name @version = version @dependencies = [] @required_ruby_version = Gem::Requirement.default @required_rubygems_version = Gem::Requirement.default @platform = platform || Gem::Platform::RUBY @original_source = source @source = source @force_ruby_platform = default_force_ruby_platform @most_specific_locked_platform = nil @materialization = nil end
公共实例方法
==(other) 点击以切换源代码
# File bundler/lazy_specification.rb, line 80 def ==(other) full_name == other.full_name end
__materialize__(candidates, fallback_to_non_installable: Bundler.frozen_bundle?) 点击以切换源代码
如果在冻结模式下,我们会回退到不可安装的候选版本,因为这样做可以避免重新解析,并可能最终更改 lock 文件,这是不允许的。 在这种情况下,我们会在尝试安装错误的 gem 之前,在堆栈的更上层提供关于不匹配的正确错误。
# File bundler/lazy_specification.rb, line 168 def __materialize__(candidates, fallback_to_non_installable: Bundler.frozen_bundle?) search = candidates.reverse.find do |spec| spec.is_a?(StubSpecification) || spec.matches_current_metadata? end if search.nil? && fallback_to_non_installable search = candidates.last elsif search && search.full_name == full_name # We don't validate locally installed dependencies but accept what's in # the lockfile instead for performance, since loading locally installed # dependencies would mean evaluating all gemspecs, which would affect # `bundler/setup` performance if search.is_a?(StubSpecification) search.dependencies = dependencies else if !source.is_a?(Source::Path) && search.runtime_dependencies.sort != dependencies.sort raise IncorrectLockfileDependencies.new(self) end search.locked_platform = platform if search.instance_of?(RemoteSpecification) || search.instance_of?(EndpointSpecification) end end search end
eql?(other) 点击以切换源代码
# File bundler/lazy_specification.rb, line 84 def eql?(other) full_name.eql?(other.full_name) end
force_ruby_platform!() 点击以切换源代码
# File bundler/lazy_specification.rb, line 205 def force_ruby_platform! @force_ruby_platform = true end
full_name() 点击以切换源代码
# File bundler/lazy_specification.rb, line 64 def full_name @full_name ||= if platform == Gem::Platform::RUBY "#{@name}-#{@version}" else "#{@name}-#{@version}-#{platform}" end end
git_version() 点击以切换源代码
# File bundler/lazy_specification.rb, line 200 def git_version return unless source.is_a?(Bundler::Source::Git) " #{source.revision[0..6]}" end
hash() 点击以切换源代码
# File bundler/lazy_specification.rb, line 88 def hash full_name.hash end
incomplete?() 点击以切换源代码
# File bundler/lazy_specification.rb, line 56 def incomplete? @materialization.nil? end
inspect() 点击以切换源代码
# File bundler/lazy_specification.rb, line 192 def inspect "#<#{self.class} @name=\"#{name}\" (#{full_name.delete_prefix("#{name}-")})>" end
lock_name() 点击以切换源代码
# File bundler/lazy_specification.rb, line 72 def lock_name @lock_name ||= name_tuple.lock_name end
materialize_for_installation() 点击以切换源代码
# File bundler/lazy_specification.rb, line 139 def materialize_for_installation source.local! if use_exact_resolved_specifications? materialize_strictly else matching_specs = source.specs.search([name, version]) return self if matching_specs.empty? target_platform = source.is_a?(Source::Path) ? platform : local_platform installable_candidates = GemHelpers.select_best_platform_match(matching_specs, target_platform) specification = __materialize__(installable_candidates, fallback_to_non_installable: false) return specification unless specification.nil? if target_platform != platform installable_candidates = GemHelpers.select_best_platform_match(matching_specs, platform) end __materialize__(installable_candidates) end end
materialize_strictly() 点击以切换源代码
# File bundler/lazy_specification.rb, line 124 def materialize_strictly source.local! matching_specs = source.specs.search(self) return self if matching_specs.empty? __materialize__(matching_specs) end
materialized_for_installation() 点击以切换源代码
# File bundler/lazy_specification.rb, line 133 def materialized_for_installation @materialization = materialize_for_installation self unless incomplete? end
missing?() 点击以切换源代码
# File bundler/lazy_specification.rb, line 52 def missing? @materialization == self end
name_tuple() 点击以切换源代码
# File bundler/lazy_specification.rb, line 76 def name_tuple Gem::NameTuple.new(@name, @version, @platform) end
satisfies?(dependency) 点击以切换源代码
此锁定的规范是否满足 dependency
?
注意:Rubygems 默认要求是“>= 0”,它与 0 版本的预发布版本不匹配,如“0.0.0.dev”或“0.0.0.SNAPSHOT”。但是,bundler 用户希望这些有效。我们需要确保没有明确要求的 Gemfile 依赖项(默认情况下在底层使用“>= 0”)对于使用此类版本的锁定规范仍然有效。该方法为此实现了一个临时的修复。更好的解决方案可能是将依赖项的默认 rubygems 要求更改为“>= 0.A”,但这可能会是一个重大的重构,可能会破坏某些东西。希望我们将来可以尝试这样做。
# File bundler/lazy_specification.rb, line 106 def satisfies?(dependency) effective_requirement = dependency.requirement == Gem::Requirement.default ? Gem::Requirement.new(">= 0.A") : dependency.requirement @name == dependency.name && effective_requirement.satisfied_by?(Gem::Version.new(@version)) end
source_changed?() 点击以切换源代码
# File bundler/lazy_specification.rb, line 60 def source_changed? @original_source != source end
to_lock() 点击以切换源代码
# File bundler/lazy_specification.rb, line 112 def to_lock out = String.new out << " #{lock_name}\n" dependencies.sort_by(&:to_s).uniq.each do |dep| next if dep.type == :development out << " #{dep.to_lock}\n" end out end
to_s() 点击以切换源代码
# File bundler/lazy_specification.rb, line 196 def to_s lock_name end
私有实例方法
ruby_platform_materializes_to_ruby_platform?() 点击以切换源代码
# File bundler/lazy_specification.rb, line 215 def ruby_platform_materializes_to_ruby_platform? generic_platform = generic_local_platform == Gem::Platform::JAVA ? Gem::Platform::JAVA : Gem::Platform::RUBY (most_specific_locked_platform != generic_platform) || force_ruby_platform || Bundler.settings[:force_ruby_platform] end
use_exact_resolved_specifications?() 点击以切换源代码
# File bundler/lazy_specification.rb, line 211 def use_exact_resolved_specifications? !source.is_a?(Source::Path) && ruby_platform_materializes_to_ruby_platform? end