class Solve::Artifact
Attributes
A reference to the graph this artifact belongs to
@return [Solve::Graph]
The name of the artifact
@return [String]
The version of this artifact
@return [Semverse::Version]
Public Class Methods
@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
@param [Semverse::Version] other
@return [Integer]
# File lib/solve/artifact.rb, line 102 def <=>(other) version <=> other.version end
@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
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
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
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
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
# File lib/solve/artifact.rb, line 85 def to_s "#{name}-#{version}" end
Private Instance Methods
# File lib/solve/artifact.rb, line 108 def get_dependency(name, constraint) @dependencies["#{name}-#{constraint}"] end
# File lib/solve/artifact.rb, line 112 def set_dependency(name, constraint) @dependencies["#{name}-#{constraint}"] = Dependency.new(self, name, constraint) end