class Solve::Artifact

Attributes

graph[R]

A reference to the graph this artifact belongs to

@return [Solve::Graph]

name[R]

The name of the artifact

@return [String]

version[R]

The version of this artifact

@return [Semverse::Version]

Public Class Methods

new(graph, name, version) click to toggle source

@param [Solve::Graph] graph @param [#to_s] name @param [Semverse::Version, to_s] version

# File lib/solve/artifact.rb, line 23
def initialize(graph, name, version)
  @graph        = graph
  @name         = name
  @version      = Semverse::Version.new(version)
  @dependencies = {}
end

Public Instance Methods

<=>(other) click to toggle source

@param [Semverse::Version] other

@return [Integer]

# File lib/solve/artifact.rb, line 102
def <=>(other)
  version <=> other.version
end
==(other) click to toggle source

@param [Object] other

@return [Boolean]

# File lib/solve/artifact.rb, line 92
def ==(other)
  other.is_a?(self.class) &&
    name == other.name &&
    version == other.version
end
Also aliased as: eql?
dependencies() click to toggle source

Return the collection of dependencies on this instance of artifact

@return [Array<Solve::Dependency>]

# File lib/solve/artifact.rb, line 55
def dependencies
  @dependencies.values
end
dependency(name, constraint) click to toggle source

Retrieve the dependency from the artifact with the matching name and constraint

@param [#to_s] name @param [#to_s] constraint

@return [Solve::Artifact, nil]

# File lib/solve/artifact.rb, line 48
def dependency(name, constraint)
  set_dependency(name, constraint)
end
dependency?(name, constraint) click to toggle source

Check if the artifact has a dependency with the matching name and constraint

@param [#to_s] name @param [#to_s] constraint

@return [Boolean]

# File lib/solve/artifact.rb, line 37
def dependency?(name, constraint)
  !get_dependency(name, constraint).nil?
end
Also aliased as: has_dependency?
depends(name, constraint = ">= 0.0.0") click to toggle source

Return the Solve::Dependency from the collection of dependencies with the given name and constraint.

@param [#to_s] name @param [String] constraint

@example Adding dependencies

artifact.depends('nginx')
  #=> #<Dependency nginx (>= 0.0.0)>
artifact.depends('ntp', '= 1.0.0')
  #=> #<Dependency ntp (= 1.0.0)>

@example Chaining dependencies

artifact
  .depends('nginx')
  .depends('ntp', '~> 1.3')

@return [Solve::Artifact]

# File lib/solve/artifact.rb, line 77
def depends(name, constraint = ">= 0.0.0")
  unless dependency?(name, constraint)
    set_dependency(name, constraint)
  end

  self
end
eql?(other)
Alias for: ==
has_dependency?(name, constraint)
Alias for: dependency?
to_s() click to toggle source
# File lib/solve/artifact.rb, line 85
def to_s
  "#{name}-#{version}"
end

Private Instance Methods

get_dependency(name, constraint) click to toggle source
# File lib/solve/artifact.rb, line 108
def get_dependency(name, constraint)
  @dependencies["#{name}-#{constraint}"]
end
set_dependency(name, constraint) click to toggle source
# File lib/solve/artifact.rb, line 112
def set_dependency(name, constraint)
  @dependencies["#{name}-#{constraint}"] = Dependency.new(self, name, constraint)
end