Class: Qricker::Resolver

Inherits:
Object
  • Object
show all
Defined in:
lib/qricker/dependency.rb

Instance Method Summary collapse

Constructor Details

#initialize(deps) ⇒ Resolver

Returns a new instance of Resolver.



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/qricker/dependency.rb', line 69

def initialize(deps)
  @roots = DependencyNode.new("root")
  @deps = deps
  deps.each { |spec|
    dependencies =  spec.podSpecilication.attributes_hash["dependencies"]
    next if  dependencies.nil?
    dependencies.each { |name , versions|
      addDependency(name, spec.name)
    }
  }
end

Instance Method Details

#addDependency(parent, child) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/qricker/dependency.rb', line 81

def addDependency(parent, child)
  parentNode = @roots.searchChild(parent)
  if parentNode.nil?
    parentNode = DependencyNode.new(parent)
    @roots.addChild(parentNode)
  end
  childNode = nil
  if @roots.hasChild(child)
    childNode = @roots.searchChild(child)
    @roots.removeChild childNode
  else
    childNode = DependencyNode.new(child)
  end
  if parentNode.searchChild(child).nil?
    parentNode.addChild(childNode)
  end
end

#printSelfObject



113
114
115
# File 'lib/qricker/dependency.rb', line 113

def printSelf
  @roots.printSelf(0)
end

#sortedObject



99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/qricker/dependency.rb', line 99

def sorted

  array = Array.new
  addSortedArray(array, @roots)
  deps = @deps.sort{|x, y|
    xIndex = array.index(x.name)
    yIndex =  array.index(y.name)
    xIndex <=> yIndex
  }

  return deps
end