Class: Doubleshot::Resolver::GemResolver::Artifact

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/doubleshot/resolver/gem_resolver/artifact.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(graph, name, version) ⇒ Artifact

Returns a new instance of Artifact.

Parameters:



25
26
27
28
29
30
# File 'lib/doubleshot/resolver/gem_resolver/artifact.rb', line 25

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

Instance Attribute Details

#graphDoubleshot::Resolver::GemResolver::Graph (readonly)

A reference to the graph this artifact belongs to



10
11
12
# File 'lib/doubleshot/resolver/gem_resolver/artifact.rb', line 10

def graph
  @graph
end

#nameString (readonly)

The name of the artifact

Returns:



15
16
17
# File 'lib/doubleshot/resolver/gem_resolver/artifact.rb', line 15

def name
  @name
end

#versionGem::Version (readonly)

The version of this artifact

Returns:

  • (Gem::Version)


20
21
22
# File 'lib/doubleshot/resolver/gem_resolver/artifact.rb', line 20

def version
  @version
end

Instance Method Details

#<=>(other) ⇒ Integer

Parameters:

  • other (Gem::Version)

Returns:

  • (Integer)


102
103
104
# File 'lib/doubleshot/resolver/gem_resolver/artifact.rb', line 102

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

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

Parameters:

Returns:

  • (Boolean)


92
93
94
95
96
# File 'lib/doubleshot/resolver/gem_resolver/artifact.rb', line 92

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

#deleteDoubleshot::Resolver::GemResolver::Artifact?

Remove this artifact from the graph it belongs to



77
78
79
80
81
82
83
# File 'lib/doubleshot/resolver/gem_resolver/artifact.rb', line 77

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

#dependenciesArray<Doubleshot::Resolver::GemResolver::Dependency>

Return the collection of dependencies on this instance of artifact



60
61
62
# File 'lib/doubleshot/resolver/gem_resolver/artifact.rb', line 60

def dependencies
  @dependencies.collect { |name, dependency| dependency }
end

#depends(name, constraint = ">= 0") ⇒ Doubleshot::Resolver::GemResolver::Artifact

Return the Doubleshot::Resolver::GemResolver::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:



46
47
48
49
50
51
52
53
54
55
# File 'lib/doubleshot/resolver/gem_resolver/artifact.rb', line 46

def depends(name, constraint = ">= 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) ⇒ Doubleshot::Resolver::GemResolver::Artifact?

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

Parameters:

Returns:



70
71
72
# File 'lib/doubleshot/resolver/gem_resolver/artifact.rb', line 70

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

#to_sObject



85
86
87
# File 'lib/doubleshot/resolver/gem_resolver/artifact.rb', line 85

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