Class: DepAnalyzer
Overview
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.
Direct Known Subclasses
FreebsdAnalyzer, HomebrewAnalyzer, MacportsAnalyzer, RakeAnalyzer, RubygemsAnalyzer
Instance Attribute Summary collapse
-
#g ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#decorate ⇒ Object
Allows your subclass to add extra fancy stuff to the graph when analysis is finished.
-
#deps(port) ⇒ Object
Return the dependencies for a given port.
-
#initialize ⇒ DepAnalyzer
constructor
:nodoc:.
-
#installed ⇒ Object
Return all installed items on the system.
-
#outdated ⇒ Object
Return all outdated items currently installed.
-
#run(argv = ARGV) ⇒ Object
Do the actual work.
-
#setup ⇒ Object
Allows subclasses to do any preparation before the run.
Methods inherited from Cache
Constructor Details
#initialize ⇒ DepAnalyzer
:nodoc:
111 112 113 114 |
# File 'lib/dep_analyzer.rb', line 111 def initialize # :nodoc: super ".#{self.class}.cache" @g = Graph.new end |
Instance Attribute Details
Instance Method Details
#decorate ⇒ Object
Allows your subclass to add extra fancy stuff to the graph when analysis is finished.
120 121 122 |
# File 'lib/dep_analyzer.rb', line 120 def decorate # nothing to do by default end |
#deps(port) ⇒ Object
Return the dependencies for a given port.
127 128 129 |
# File 'lib/dep_analyzer.rb', line 127 def deps port raise NotImplementedError, "subclass responsibility" end |
#installed ⇒ Object
Return all installed items on the system.
134 135 136 |
# File 'lib/dep_analyzer.rb', line 134 def installed raise NotImplementedError, "subclass responsibility" end |
#outdated ⇒ Object
Return all outdated items currently installed.
141 142 143 |
# File 'lib/dep_analyzer.rb', line 141 def outdated raise NotImplementedError, "subclass responsibility" end |
#run(argv = ARGV) ⇒ Object
Do the actual work.
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# 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 ⇒ Object
Allows subclasses to do any preparation before the run.
219 220 221 |
# File 'lib/dep_analyzer.rb', line 219 def setup # nothing to do by default end |