class DepAnalyzer

Abstract class to analyze dependencies. Intended to be subclassed for a given dependency system (eg rubygems). Subclasses must implement deps, installed, and outdated at the very least.

Public Instance Methods

decorate() click to toggle source

Allows your subclass to add extra fancy stuff to the graph when analysis is finished.

# File lib/dep_analyzer.rb, line 120
def decorate
  # nothing to do by default
end
deps(port) click to toggle source

Return the dependencies for a given port.

# File lib/dep_analyzer.rb, line 127
def deps port
  raise NotImplementedError, "subclass responsibility"
end
installed() click to toggle source

Return all installed items on the system.

# File lib/dep_analyzer.rb, line 134
def installed
  raise NotImplementedError, "subclass responsibility"
end
outdated() click to toggle source

Return all outdated items currently installed.

# File lib/dep_analyzer.rb, line 141
def outdated
  raise NotImplementedError, "subclass responsibility"
end
run(argv = ARGV) click to toggle source

Do the actual work.

# File lib/dep_analyzer.rb, line 148
def run(argv = ARGV)
  setup

  ports = {}
  installed.each do |port|
    ports[port] = nil
  end

  old = {}
  outdated.each do |port|
    old[port] = nil
  end

  all_ports = ports.keys

  ports.each_key do |port|
    deps = self.deps(port)
    # remove things that don't intersect with installed list
    deps -= (deps - all_ports)
    deps.each do |dep|
      g[port] << dep
    end
    ports[port] = deps
  end

  rect   = g.rect
  blue   = g.color "blue"
  purple = g.color "purple4"
  red    = g.color "red"
  pink   = g.fill_lightpink

  indies = ports.keys - ports.minvert.keys
  indies.each do |k|
    rect << g[k]
    blue << g[k]
  end

  old.each do |k,v|
    pink << g[k]
    if indies.include? k then
      purple << g[k]
    else
      red << g[k]
    end
  end

  decorate

  puts "Looks like you can nuke:\n\t#{indies.sort.join("\n\t")}"

  unless argv.empty? then
    argv.each do |pkg|
      hits = ports.transitive[pkg]
      sorted = ports.tsort.reverse
      topo = [pkg] + sorted.select { |o| hits.include? o }
      prune = ports.dup
      topo.each do |k|
        prune.delete(k)
      end
      topo -= prune.values.flatten.uniq

      puts topo.join(' ')
    end
  end

  g
end
setup() click to toggle source

Allows subclasses to do any preparation before the run.

# File lib/dep_analyzer.rb, line 219
def setup
  # nothing to do by default
end