Class: Librarian::ManifestSet
- Inherits:
-
Object
- Object
- Librarian::ManifestSet
- Defined in:
- lib/librarian/manifest_set.rb
Class Method Summary collapse
- .cyclic?(manifests) ⇒ Boolean
- .deep_keep(manifests, names) ⇒ Object
- .deep_strip(manifests, names) ⇒ Object
- .shallow_keep(manifests, names) ⇒ Object
- .shallow_strip(manifests, names) ⇒ Object
- .sort(manifests) ⇒ Object
Instance Method Summary collapse
- #consistent? ⇒ Boolean
- #deep_keep(names) ⇒ Object
- #deep_keep!(names) ⇒ Object
- #deep_strip(names) ⇒ Object
- #deep_strip!(names) ⇒ Object
- #dup ⇒ Object
- #in_compliance_with?(dependencies) ⇒ Boolean
-
#initialize(manifests) ⇒ ManifestSet
constructor
A new instance of ManifestSet.
- #shallow_keep(names) ⇒ Object
- #shallow_keep!(names) ⇒ Object
- #shallow_strip(names) ⇒ Object
- #shallow_strip!(names) ⇒ Object
- #to_a ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(manifests) ⇒ ManifestSet
Returns a new instance of ManifestSet.
44 45 46 |
# File 'lib/librarian/manifest_set.rb', line 44 def initialize(manifests) self.index = Hash === manifests ? manifests.dup : index_by(manifests, &:name) end |
Class Method Details
.cyclic?(manifests) ⇒ Boolean
19 20 21 22 23 |
# 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) ⇒ Object
16 17 18 |
# 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) ⇒ Object
10 11 12 |
# File 'lib/librarian/manifest_set.rb', line 10 def deep_strip(manifests, names) new(manifests).deep_strip!(names).send(method_for(manifests)) end |
.shallow_keep(manifests, names) ⇒ Object
13 14 15 |
# 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) ⇒ Object
7 8 9 |
# 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) ⇒ Object
24 25 26 27 28 29 |
# 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 |
Instance Method Details
#consistent? ⇒ Boolean
107 108 109 110 111 |
# 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) ⇒ Object
96 97 98 |
# File 'lib/librarian/manifest_set.rb', line 96 def deep_keep(names) dup.conservative_strip!(names) end |
#deep_keep!(names) ⇒ Object
100 101 102 103 104 105 |
# File 'lib/librarian/manifest_set.rb', line 100 def deep_keep!(names) keepables = dependencies_of(names) shallow_keep!(keepables) self end |
#deep_strip(names) ⇒ Object
73 74 75 |
# File 'lib/librarian/manifest_set.rb', line 73 def deep_strip(names) dup.deep_strip!(names) end |
#deep_strip!(names) ⇒ Object
77 78 79 80 81 82 |
# File 'lib/librarian/manifest_set.rb', line 77 def deep_strip!(names) strippables = dependencies_of(names) shallow_strip!(strippables) self end |
#dup ⇒ Object
56 57 58 |
# File 'lib/librarian/manifest_set.rb', line 56 def dup self.class.new(index) end |
#in_compliance_with?(dependencies) ⇒ Boolean
113 114 115 116 117 118 |
# 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) ⇒ Object
84 85 86 |
# File 'lib/librarian/manifest_set.rb', line 84 def shallow_keep(names) dup.shallow_keep!(names) end |
#shallow_keep!(names) ⇒ Object
88 89 90 91 92 93 94 |
# 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) ⇒ Object
60 61 62 |
# File 'lib/librarian/manifest_set.rb', line 60 def shallow_strip(names) dup.shallow_strip!(names) end |
#shallow_strip!(names) ⇒ Object
64 65 66 67 68 69 70 71 |
# 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 ⇒ Object
48 49 50 |
# File 'lib/librarian/manifest_set.rb', line 48 def to_a index.values end |
#to_hash ⇒ Object
52 53 54 |
# File 'lib/librarian/manifest_set.rb', line 52 def to_hash index.dup end |