Class: Solve::Artifact

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/solve/artifact.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(graph, name, version) ⇒ Artifact

Returns a new instance of Artifact.

Parameters:



23
24
25
26
27
28
# File 'lib/solve/artifact.rb', line 23

def initialize(graph, name, version)
  @graph        = graph
  @name         = name
  @version      = Semverse::Version.new(version)
  @dependencies = {}
end

Instance Attribute Details

#graphSolve::Graph (readonly)

A reference to the graph this artifact belongs to

Returns:



8
9
10
# File 'lib/solve/artifact.rb', line 8

def graph
  @graph
end

#nameString (readonly)

The name of the artifact

Returns:

  • (String)


13
14
15
# File 'lib/solve/artifact.rb', line 13

def name
  @name
end

#versionSemverse::Version (readonly)

The version of this artifact

Returns:

  • (Semverse::Version)


18
19
20
# File 'lib/solve/artifact.rb', line 18

def version
  @version
end

Instance Method Details

#<=>(other) ⇒ Integer

Parameters:

  • other (Semverse::Version)

Returns:

  • (Integer)


102
103
104
# File 'lib/solve/artifact.rb', line 102

def <=>(other)
  version <=> other.version
end

#==(other) ⇒ Boolean Also known as: eql?

Parameters:

  • other (Object)

Returns:

  • (Boolean)


92
93
94
95
96
# File 'lib/solve/artifact.rb', line 92

def ==(other)
  other.is_a?(self.class) &&
    name == other.name &&
    version == other.version
end

#dependenciesArray<Solve::Dependency>

Return the collection of dependencies on this instance of artifact

Returns:



55
56
57
# File 'lib/solve/artifact.rb', line 55

def dependencies
  @dependencies.values
end

#dependency(name, constraint) ⇒ Solve::Artifact?

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

Parameters:

Returns:



48
49
50
# File 'lib/solve/artifact.rb', line 48

def dependency(name, constraint)
  set_dependency(name, constraint)
end

#dependency?(name, constraint) ⇒ Boolean Also known as: has_dependency?

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

Parameters:

Returns:

  • (Boolean)


37
38
39
# File 'lib/solve/artifact.rb', line 37

def dependency?(name, constraint)
  !get_dependency(name, constraint).nil?
end

#depends(name, constraint = ">= 0.0.0") ⇒ Solve::Artifact

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

Examples:

Adding dependencies

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

Chaining dependencies

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

Parameters:

  • name (#to_s)
  • constraint (String) (defaults to: ">= 0.0.0")

Returns:



77
78
79
80
81
82
83
# 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

#to_sObject



85
86
87
# File 'lib/solve/artifact.rb', line 85

def to_s
  "#{name}-#{version}"
end