lib/bundler/lazy_specification.rb in bundler-2.4.2 vs lib/bundler/lazy_specification.rb in bundler-2.4.3

- old
+ new

@@ -14,11 +14,10 @@ @name = name @version = version @dependencies = [] @platform = platform || Gem::Platform::RUBY @source = source - @specification = nil @force_ruby_platform = default_force_ruby_platform end def full_name if platform == Gem::Platform::RUBY @@ -78,43 +77,47 @@ end def materialize_for_installation source.local! - candidates = if source.is_a?(Source::Path) || !ruby_platform_materializes_to_ruby_platform? - target_platform = ruby_platform_materializes_to_ruby_platform? ? platform : local_platform + matching_specs = source.specs.search(use_exact_resolved_specifications? ? self : [name, version]) + return self if matching_specs.empty? - GemHelpers.select_best_platform_match(source.specs.search([name, version]), target_platform) + candidates = if use_exact_resolved_specifications? + matching_specs else - source.specs.search(self) - end + target_platform = ruby_platform_materializes_to_ruby_platform? ? platform : local_platform - return self if candidates.empty? + installable_candidates = GemHelpers.select_best_platform_match(matching_specs, target_platform) + specification = __materialize__(installable_candidates) + return specification unless specification.nil? + + if target_platform != platform + installable_candidates = GemHelpers.select_best_platform_match(matching_specs, platform) + end + + installable_candidates + end + __materialize__(candidates) end def __materialize__(candidates) - @specification = begin - search = candidates.reverse.find do |spec| - spec.is_a?(StubSpecification) || - (spec.matches_current_ruby? && - spec.matches_current_rubygems?) - end - if search.nil? && Bundler.frozen_bundle? - search = candidates.last - else - search.dependencies = dependencies if search && search.full_name == full_name && (search.is_a?(RemoteSpecification) || search.is_a?(EndpointSpecification)) - end - search + search = candidates.reverse.find do |spec| + spec.is_a?(StubSpecification) || + (spec.matches_current_ruby? && + spec.matches_current_rubygems?) end + if search.nil? && Bundler.frozen_bundle? + search = candidates.last + else + search.dependencies = dependencies if search && search.full_name == full_name && (search.is_a?(RemoteSpecification) || search.is_a?(EndpointSpecification)) + end + search end - def respond_to?(*args) - super || @specification ? @specification.respond_to?(*args) : nil - end - def to_s @__to_s ||= if platform == Gem::Platform::RUBY "#{name} (#{version})" else "#{name} (#{version}-#{platform})" @@ -130,19 +133,11 @@ " #{source.revision[0..6]}" end private - def to_ary - nil - end - - def method_missing(method, *args, &blk) - raise "LazySpecification has not been materialized yet (calling :#{method} #{args.inspect})" unless @specification - - return super unless respond_to?(method) - - @specification.send(method, *args, &blk) + def use_exact_resolved_specifications? + @use_exact_resolved_specifications ||= !source.is_a?(Source::Path) && ruby_platform_materializes_to_ruby_platform? end # # For backwards compatibility with existing lockfiles, if the most specific # locked platform is not a specific platform like x86_64-linux or