Class: Solve::Artifact

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

Overview

Author:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(graph, name, version) ⇒ Artifact

Returns a new instance of Artifact.

Parameters:



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

def initialize(graph, name, version)
  @graph = graph
  @name = name
  @version = Version.new(version)
  @dependencies = Hash.new
end

Instance Attribute Details

#graphSolve::Graph (readonly)

A reference to the graph this artifact belongs to

Returns:



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

def graph
  @graph
end

#nameString (readonly)

The name of the artifact

Returns:

  • (String)


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

def name
  @name
end

#versionSolve::Version (readonly)

The version of this artifact

Returns:



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

def version
  @version
end

Instance Method Details

#<=>(other) ⇒ Integer

Parameters:

Returns:

  • (Integer)


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

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

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

Parameters:

  • other (Object)

Returns:

  • (Boolean)


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

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

#deleteSolve::Artifact?

Remove this artifact from the graph it belongs to

Returns:



76
77
78
79
80
81
82
# File 'lib/solve/artifact.rb', line 76

def delete
  unless graph.nil?
    result = graph.remove_artifact(self)
    @graph = nil
    result
  end
end

#dependenciesArray<Solve::Dependency>

Return the collection of dependencies on this instance of artifact

Returns:



59
60
61
# File 'lib/solve/artifact.rb', line 59

def dependencies
  @dependencies.collect { |name, dependency| dependency }
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: @name="nginx", @constraint=">= 0.0.0">
artifact.depends("ntp", "= 1.0.0") => <#Dependency: @name="ntp", @constraint="= 1.0.0">

chaining dependencies

artifact.depends("nginx").depends("ntp")

Parameters:

Returns:



45
46
47
48
49
50
51
52
53
54
# File 'lib/solve/artifact.rb', line 45

def depends(name, constraint = ">= 0.0.0")
  if name.nil?
    raise ArgumentError, "A name must be specified. You gave: #{args}."
  end

  dependency = Dependency.new(self, name, constraint)
  add_dependency(dependency)

  self
end

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

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

Parameters:

Returns:



69
70
71
# File 'lib/solve/artifact.rb', line 69

def get_dependency(name, constraint)
  @dependencies.fetch(Graph.dependency_key(name, constraint), nil)
end

#to_sObject



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

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