class Librarian::ManifestSet
Attributes
index[RW]
Public Class Methods
cyclic?(manifests)
click to toggle source
# File lib/librarian/manifest_set.rb, line 19 def cyclic?(manifests) manifests = Hash[manifests.map{|m| [m.name, m]}] if Array === manifests manifest_pairs = Hash[manifests.map{|k, m| [k, m.dependencies.map{|d| d.name}]}] adj_algs.cyclic?(manifest_pairs) end
deep_keep(manifests, names)
click to toggle source
# File lib/librarian/manifest_set.rb, line 16 def deep_keep(manifests, names) new(manifests).deep_keep!(names).send(method_for(manifests)) end
deep_strip(manifests, names)
click to toggle source
# File lib/librarian/manifest_set.rb, line 10 def deep_strip(manifests, names) new(manifests).deep_strip!(names).send(method_for(manifests)) end
new(manifests)
click to toggle source
# File lib/librarian/manifest_set.rb, line 44 def initialize(manifests) self.index = Hash === manifests ? manifests.dup : index_by(manifests, &:name) end
shallow_keep(manifests, names)
click to toggle source
# File lib/librarian/manifest_set.rb, line 13 def shallow_keep(manifests, names) new(manifests).shallow_keep!(names).send(method_for(manifests)) end
shallow_strip(manifests, names)
click to toggle source
# File lib/librarian/manifest_set.rb, line 7 def shallow_strip(manifests, names) new(manifests).shallow_strip!(names).send(method_for(manifests)) end
sort(manifests)
click to toggle source
# File lib/librarian/manifest_set.rb, line 24 def sort(manifests) manifests = Hash[manifests.map{|m| [m.name, m]}] if Array === manifests manifest_pairs = Hash[manifests.map{|k, m| [k, m.dependencies.map{|d| d.name}]}] manifest_names = adj_algs.tsort_cyclic(manifest_pairs) manifest_names.map{|n| manifests[n]} end
Private Class Methods
adj_algs()
click to toggle source
# File lib/librarian/manifest_set.rb, line 39 def adj_algs Algorithms::AdjacencyListDirectedGraph end
method_for(manifests)
click to toggle source
# File lib/librarian/manifest_set.rb, line 31 def method_for(manifests) case manifests when Hash :to_hash when Array :to_a end end
Public Instance Methods
consistent?()
click to toggle source
# File lib/librarian/manifest_set.rb, line 107 def consistent? index.values.all? do |manifest| in_compliance_with?(manifest.dependencies) end end
deep_keep(names)
click to toggle source
# File lib/librarian/manifest_set.rb, line 96 def deep_keep(names) dup.conservative_strip!(names) end
deep_keep!(names)
click to toggle source
# File lib/librarian/manifest_set.rb, line 100 def deep_keep!(names) keepables = dependencies_of(names) shallow_keep!(keepables) self end
deep_strip(names)
click to toggle source
# File lib/librarian/manifest_set.rb, line 73 def deep_strip(names) dup.deep_strip!(names) end
deep_strip!(names)
click to toggle source
# File lib/librarian/manifest_set.rb, line 77 def deep_strip!(names) strippables = dependencies_of(names) shallow_strip!(strippables) self end
dup()
click to toggle source
# File lib/librarian/manifest_set.rb, line 56 def dup self.class.new(index) end
in_compliance_with?(dependencies)
click to toggle source
# File lib/librarian/manifest_set.rb, line 113 def in_compliance_with?(dependencies) dependencies.all? do |dependency| manifest = index[dependency.name] manifest && manifest.satisfies?(dependency) end end
shallow_keep(names)
click to toggle source
# File lib/librarian/manifest_set.rb, line 84 def shallow_keep(names) dup.shallow_keep!(names) end
shallow_keep!(names)
click to toggle source
# File lib/librarian/manifest_set.rb, line 88 def shallow_keep!(names) assert_strings!(names) names = Set.new(names) unless Set === names index.reject! { |k, v| !names.include?(k) } self end
shallow_strip(names)
click to toggle source
# File lib/librarian/manifest_set.rb, line 60 def shallow_strip(names) dup.shallow_strip!(names) end
shallow_strip!(names)
click to toggle source
# File lib/librarian/manifest_set.rb, line 64 def shallow_strip!(names) assert_strings!(names) names.each do |name| index.delete(name) end self end
to_a()
click to toggle source
# File lib/librarian/manifest_set.rb, line 48 def to_a index.values end
to_hash()
click to toggle source
# File lib/librarian/manifest_set.rb, line 52 def to_hash index.dup end
Private Instance Methods
assert_strings!(names)
click to toggle source
# File lib/librarian/manifest_set.rb, line 124 def assert_strings!(names) non_strings = names.reject{|name| String === name} non_strings.empty? or raise TypeError, "names must all be strings" end
dependencies_of(names)
click to toggle source
Straightforward breadth-first graph traversal algorithm.
# File lib/librarian/manifest_set.rb, line 130 def dependencies_of(names) names = Array === names ? names.dup : names.to_a assert_strings!(names) deps = Set.new until names.empty? name = names.shift next if deps.include?(name) deps << name raise(Error, "Unable to find module #{name}. The dependency descriptor may be out of sync with the lock, try running 'install' first") if index[name].nil? names.concat index[name].dependencies.map(&:name) end deps.to_a end
index_by(enum)
click to toggle source
# File lib/librarian/manifest_set.rb, line 146 def index_by(enum) Hash[enum.map{|obj| [yield(obj), obj]}] end