Parent

DepSelector::Package

Attributes

dependency_graph[R]
name[R]
versions[R]

Public Class Methods

new(dependency_graph, name) click to toggle source
# File lib/dep_selector/package.rb, line 27
def initialize(dependency_graph, name)
  @dependency_graph = dependency_graph
  @name = name
  @versions = []
end

Public Instance Methods

==(o) click to toggle source
Alias for: eql?
[](version_or_constraint) click to toggle source

Given a version, this method returns the corresonding PackageVersion. Given a version constraint, this method returns an array of matching PackageVersions.

# File lib/dep_selector/package.rb, line 48
def [](version_or_constraint)
  # version constraints must abide the include? contract
  if version_or_constraint.respond_to?(:include?)
    versions.select do |ver|
      version_or_constraint.include?(ver)
    end
  else
    versions.find{|pkg_version| pkg_version.version == version_or_constraint}
  end
end
add_version(version) click to toggle source
# File lib/dep_selector/package.rb, line 33
def add_version(version)
  versions << (pv = PackageVersion.new(self, version))
  pv
end
densely_packed_versions() click to toggle source

Note: only invoke this method after all PackageVersions have been added

# File lib/dep_selector/package.rb, line 39
def densely_packed_versions
  @densely_packed_versions ||= DenselyPackedSet.new(versions.map{|pkg_version| pkg_version.version})
end
eql?(o) click to toggle source
# File lib/dep_selector/package.rb, line 108
def eql?(o)
  # TODO [cw,2011/2/7]: this is really shallow. should implement
  # == for DependencyGraph
  self.class == o.class && name == o.name
end
Also aliased as: ==
gecode_package_id() click to toggle source

Note: only invoke this method after all PackageVersions have been added

# File lib/dep_selector/package.rb, line 75
def gecode_package_id
  # Note: gecode does naive bounds propagation at every post,
  # which means that any package with exactly one version is
  # considered bound and its dependencies propagated even though
  # there might not be a solution constraint that requires that
  # package to be bound, which means that otherwise-irrelevant
  # constraints (e.g. A1->B1 when the solution constraint is B=2
  # and there is nothing to induce a dependency on A) can cause
  # unsatisfiability. Therefore, we want every package to have at
  # least two versions, one of which is neither the target of
  # other packages' dependencies nor induces other
  # dependencies. Package version id -1 serves this purpose.
  #
  # TODO [cw, 2011/2/22]: Do we likewise want to leave packages
  # with no versions (the target of an invalid dependency) with
  # two versions in order to allow the solver to explore the
  # invalid portion of the state space instead of naively limiting
  # it for the purposes of having failure count heuristics?
  max = densely_packed_versions.range.max || -1
  @gecode_package_id ||= dependency_graph.gecode_wrapper.add_package(-1, max, 0)
end
generate_gecode_wrapper_constraints() click to toggle source
# File lib/dep_selector/package.rb, line 97
def generate_gecode_wrapper_constraints
  # if this is a valid package (has versions), we don't need to
  # explicitly call gecode_package_id, because they will do it for
  # us; however, if this package isn't valid (it only exists as an
  # invalid dependency and thus has no versions), the solver gets
  # confused, because we won't have generated its package id by
  # the time it starts solving.
  gecode_package_id
  versions.each{|version| version.generate_gecode_wrapper_constraints }
end
to_s(incl_densely_packed_versions = false) click to toggle source
# File lib/dep_selector/package.rb, line 64
def to_s(incl_densely_packed_versions = false)
  components = []
  components << "Package #{name}"
  if incl_densely_packed_versions
    components << " (#{densely_packed_versions.range})"
  end
  versions.each{|version| components << "\n  #{version.to_s(incl_densely_packed_versions)}"}
  components.flatten.join
end
valid?() click to toggle source

A Package is considered valid if it has at least one version

# File lib/dep_selector/package.rb, line 60
def valid?
  versions.any?
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.