Sha256: cb71a8d5dfbe2474ae803eb4ea978541d8bea0bd08defb188f68f2cbf8eaef96

Contents?: true

Size: 1.16 KB

Versions: 9

Compression:

Stored size: 1.16 KB

Contents

require 'pub_grub/package'
require 'pub_grub/version_constraint'
require 'pub_grub/incompatibility'
require 'pub_grub/basic_package_source'

module 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] = deps
      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)

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
pub_grub-0.5.0 lib/pub_grub/static_package_source.rb
pub_grub-0.5.0.alpha3 lib/pub_grub/static_package_source.rb
pub_grub-0.5.0.alpha2 lib/pub_grub/static_package_source.rb
pub_grub-0.5.0.alpha1 lib/pub_grub/static_package_source.rb
pub_grub-0.5.0.alpha lib/pub_grub/static_package_source.rb
pub_grub-0.4.3 lib/pub_grub/static_package_source.rb
pub_grub-0.4.2 lib/pub_grub/static_package_source.rb
pub_grub-0.4.1 lib/pub_grub/static_package_source.rb
pub_grub-0.4.0 lib/pub_grub/static_package_source.rb