Sha256: 00523d7beb65747265c54236b8adc10ab7f6b45850756dbe19122e8687fc02ca

Contents?: true

Size: 1.79 KB

Versions: 124

Compression:

Stored size: 1.79 KB

Contents

# frozen_string_literal: true

module Bundler
  class Resolver
    class SpecGroup
      def initialize(specs)
        @specs = specs
      end

      def empty?
        @specs.empty?
      end

      def name
        @name ||= exemplary_spec.name
      end

      def version
        @version ||= exemplary_spec.version
      end

      def source
        @source ||= exemplary_spec.source
      end

      def to_specs(force_ruby_platform)
        @specs.map do |s|
          lazy_spec = LazySpecification.new(name, version, s.platform, source)
          lazy_spec.force_ruby_platform = force_ruby_platform
          lazy_spec.dependencies.replace s.dependencies
          lazy_spec
        end
      end

      def to_s
        sorted_spec_names.join(", ")
      end

      def dependencies
        @dependencies ||= @specs.map do |spec|
          __dependencies(spec) + metadata_dependencies(spec)
        end.flatten.uniq
      end

      protected

      def sorted_spec_names
        @sorted_spec_names ||= @specs.map(&:full_name).sort
      end

      private

      def exemplary_spec
        @specs.first
      end

      def __dependencies(spec)
        dependencies = []
        spec.dependencies.each do |dep|
          next if dep.type == :development
          dependencies << Dependency.new(dep.name, dep.requirement)
        end
        dependencies
      end

      def metadata_dependencies(spec)
        return [] if spec.is_a?(LazySpecification)

        [
          metadata_dependency("Ruby", spec.required_ruby_version),
          metadata_dependency("RubyGems", spec.required_rubygems_version),
        ].compact
      end

      def metadata_dependency(name, requirement)
        return if requirement.nil? || requirement.none?

        Dependency.new("#{name}\0", requirement)
      end
    end
  end
end

Version data entries

124 entries across 124 versions & 4 rubygems

Version Path
direct7-0.0.18 vendor/bundle/ruby/2.7.0/gems/bundler-2.4.21/lib/bundler/resolver/spec_group.rb
direct7-0.0.17 vendor/bundle/ruby/2.7.0/gems/bundler-2.4.21/lib/bundler/resolver/spec_group.rb
direct7-0.0.16 vendor/bundle/ruby/2.7.0/gems/bundler-2.4.21/lib/bundler/resolver/spec_group.rb
harbr-2.8.1 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/resolver/spec_group.rb
direct7-0.0.13 vendor/bundle/ruby/2.7.0/gems/bundler-2.4.21/lib/bundler/resolver/spec_group.rb
direct7-0.0.12 vendor/bundle/ruby/2.7.0/gems/bundler-2.4.21/lib/bundler/resolver/spec_group.rb
harbr-0.2.10 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/resolver/spec_group.rb
harbr-0.2.9 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/resolver/spec_group.rb
harbr-0.2.8 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/resolver/spec_group.rb
harbr-0.2.7 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/resolver/spec_group.rb
harbr-0.2.6 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/resolver/spec_group.rb
harbr-0.2.5 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/resolver/spec_group.rb
harbr-0.2.4 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/resolver/spec_group.rb
harbr-0.2.3 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/resolver/spec_group.rb
harbr-0.2.2 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/resolver/spec_group.rb
harbr-0.2.1 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/resolver/spec_group.rb
harbr-0.2.0 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/resolver/spec_group.rb
harbr-0.1.99 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/resolver/spec_group.rb
harbr-0.1.98 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/resolver/spec_group.rb
harbr-0.1.97 vendor/bundle/ruby/3.2.0/gems/bundler-2.4.21/lib/bundler/resolver/spec_group.rb