Sha256: ae81574c4c7501ca2ebde207ec6e5ff4cd5ffdb66c0c26d2704a15c5a46a9e5f

Contents?: true

Size: 1.47 KB

Versions: 41

Compression:

Stored size: 1.47 KB

Contents

require_relative 'package'
require_relative 'rubygems'
require_relative 'version_constraint'
require_relative 'incompatibility'
require_relative 'basic_package_source'

module Bundler::PubGrub
  class StaticPackageSource < BasicPackageSource
    class DSL
      def initialize(packages, root_deps)
        @packages = packages
        @root_deps = root_deps
      end

      def root(deps:)
        @root_deps.update(deps)
      end

      def add(name, version, deps: {})
        version = Gem::Version.new(version)
        @packages[name] ||= {}
        raise ArgumentError, "#{name} #{version} declared twice" if @packages[name].key?(version)
        @packages[name][version] = clean_deps(name, version, deps)
      end

      private

      # Exclude redundant self-referencing dependencies
      def clean_deps(name, version, deps)
        deps.reject {|dep_name, req| name == dep_name && Bundler::PubGrub::RubyGems.parse_range(req).include?(version) }
      end
    end

    def initialize
      @root_deps = {}
      @packages = {}

      yield DSL.new(@packages, @root_deps)

      super()
    end

    def all_versions_for(package)
      @packages[package].keys
    end

    def root_dependencies
      @root_deps
    end

    def dependencies_for(package, version)
      @packages[package][version]
    end

    def parse_dependency(package, dependency)
      return false unless @packages.key?(package)

      Bundler::PubGrub::RubyGems.parse_constraint(package, dependency)
    end
  end
end

Version data entries

41 entries across 41 versions & 3 rubygems

Version Path
bundler-2.5.18 lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb
rubygems-update-3.5.17 bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb
bundler-2.5.17 lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb
rubygems-update-3.5.16 bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb
bundler-2.5.16 lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb
rubygems-update-3.5.15 bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb
bundler-2.5.15 lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb
rubygems-update-3.5.14 bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb
bundler-2.5.14 lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb
rubygems-update-3.5.13 bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb
bundler-2.5.13 lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb
rubygems-update-3.5.12 bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb
bundler-2.5.12 lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb
rubygems-update-3.5.10 bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb
bundler-2.5.10 lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb
rubygems-update-3.5.9 bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb
bundler-2.5.9 lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb
rubygems-update-3.5.8 bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb
bundler-2.5.8 lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb
rubygems-update-3.5.7 bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb