class Solve::Graph

Public Class Methods

new() click to toggle source
# File lib/solve/graph.rb, line 3
def initialize
  @artifacts = {}
  @artifacts_by_name = Hash.new { |hash, key| hash[key] = [] }
end

Public Instance Methods

==(other) click to toggle source

@param [Object] other

@return [Boolean]

# File lib/solve/graph.rb, line 66
def ==(other)
  return false unless other.is_a?(Graph)
  return false unless artifacts.size == other.artifacts.size

  self_artifacts = artifacts
  other_artifacts = other.artifacts

  self_dependencies = self_artifacts.inject([]) do |list, artifact|
    list << artifact.dependencies
  end.flatten

  other_dependencies = other_artifacts.inject([]) do |list, artifact|
    list << artifact.dependencies
  end.flatten

  self_dependencies.size == other_dependencies.size &&
    self_artifacts.all? { |artifact| other_artifacts.include?(artifact) } &&
    self_dependencies.all? { |dependency| other_dependencies.include?(dependency) }
end
Also aliased as: eql?
artifact(name, version) click to toggle source

Add an artifact to the graph

@param [String] name @Param [String] version

# File lib/solve/graph.rb, line 28
def artifact(name, version)
  unless artifact?(name, version)
    artifact = Artifact.new(self, name, version)
    @artifacts["#{name}-#{version}"] = artifact
    @artifacts_by_name[name] << artifact
  end

  @artifacts["#{name}-#{version}"]
end
artifact?(name, version) click to toggle source

Check if an artifact with a matching name and version is a member of this instance of graph

@param [String] name @param [Semverse::Version, to_s] version

@return [Boolean]

# File lib/solve/graph.rb, line 15
def artifact?(name, version)
  !find(name, version).nil?
end
Also aliased as: has_artifact?
artifacts() click to toggle source

Return the collection of artifacts

@return [Array<Solve::Artifact>]

# File lib/solve/graph.rb, line 41
def artifacts
  @artifacts.values
end
eql?(other)
Alias for: ==
find(name, version) click to toggle source
# File lib/solve/graph.rb, line 20
def find(name, version)
  @artifacts["#{name}-#{version}"]
end
has_artifact?(name, version)
Alias for: artifact?
versions(name, constraint = Semverse::DEFAULT_CONSTRAINT) click to toggle source

Return all the artifacts from the collection of artifacts with the given name.

@param [String] name

@return [Array<Solve::Artifact>]

# File lib/solve/graph.rb, line 51
def versions(name, constraint = Semverse::DEFAULT_CONSTRAINT)
  constraint = Semverse::Constraint.coerce(constraint)

  if constraint == Semverse::DEFAULT_CONSTRAINT
    @artifacts_by_name[name]
  else
    @artifacts_by_name[name].select do |artifact|
      constraint.satisfies?(artifact.version)
    end
  end
end