Class: Librarian::ManifestSet
- Inherits:
-
Object
- Object
- Librarian::ManifestSet
- Defined in:
- lib/librarian/manifest_set.rb
Defined Under Namespace
Classes: GraphHash
Class Method Summary collapse
- .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.
45 46 47 |
# File 'lib/librarian/manifest_set.rb', line 45 def initialize(manifests) self.index = Hash === manifests ? manifests.dup : index_by(manifests, &:name) end |
Class Method Details
.deep_keep(manifests, names) ⇒ Object
25 26 27 |
# File 'lib/librarian/manifest_set.rb', line 25 def deep_keep(manifests, names) new(manifests).deep_keep!(names).send(method_for(manifests)) end |
.deep_strip(manifests, names) ⇒ Object
19 20 21 |
# File 'lib/librarian/manifest_set.rb', line 19 def deep_strip(manifests, names) new(manifests).deep_strip!(names).send(method_for(manifests)) end |
.shallow_keep(manifests, names) ⇒ Object
22 23 24 |
# File 'lib/librarian/manifest_set.rb', line 22 def shallow_keep(manifests, names) new(manifests).shallow_keep!(names).send(method_for(manifests)) end |
.shallow_strip(manifests, names) ⇒ Object
16 17 18 |
# File 'lib/librarian/manifest_set.rb', line 16 def shallow_strip(manifests, names) new(manifests).shallow_strip!(names).send(method_for(manifests)) end |
.sort(manifests) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/librarian/manifest_set.rb', line 28 def sort(manifests) manifests = Hash[manifests.map{|m| [m.name, m]}] if Array === manifests manifest_pairs = GraphHash[manifests.map{|k, m| [k, m.dependencies.map{|d| d.name}]}] manifest_names = manifest_pairs.tsort manifest_names.map{|n| manifests[n]} end |
Instance Method Details
#consistent? ⇒ Boolean
108 109 110 111 112 |
# File 'lib/librarian/manifest_set.rb', line 108 def consistent? index.values.all? do |manifest| in_compliance_with?(manifest.dependencies) end end |
#deep_keep(names) ⇒ Object
97 98 99 |
# File 'lib/librarian/manifest_set.rb', line 97 def deep_keep(names) dup.conservative_strip!(names) end |
#deep_keep!(names) ⇒ Object
101 102 103 104 105 106 |
# File 'lib/librarian/manifest_set.rb', line 101 def deep_keep!(names) keepables = dependencies_of(names) shallow_keep!(keepables) self end |
#deep_strip(names) ⇒ Object
74 75 76 |
# File 'lib/librarian/manifest_set.rb', line 74 def deep_strip(names) dup.deep_strip!(names) end |
#deep_strip!(names) ⇒ Object
78 79 80 81 82 83 |
# File 'lib/librarian/manifest_set.rb', line 78 def deep_strip!(names) strippables = dependencies_of(names) shallow_strip!(strippables) self end |
#dup ⇒ Object
57 58 59 |
# File 'lib/librarian/manifest_set.rb', line 57 def dup self.class.new(index) end |
#in_compliance_with?(dependencies) ⇒ Boolean
114 115 116 117 118 119 |
# File 'lib/librarian/manifest_set.rb', line 114 def in_compliance_with?(dependencies) dependencies.all? do |dependency| manifest = index[dependency.name] manifest && manifest.satisfies?(dependency) end end |
#shallow_keep(names) ⇒ Object
85 86 87 |
# File 'lib/librarian/manifest_set.rb', line 85 def shallow_keep(names) dup.shallow_keep!(names) end |
#shallow_keep!(names) ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/librarian/manifest_set.rb', line 89 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
61 62 63 |
# File 'lib/librarian/manifest_set.rb', line 61 def shallow_strip(names) dup.shallow_strip!(names) end |
#shallow_strip!(names) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/librarian/manifest_set.rb', line 65 def shallow_strip!(names) assert_strings!(names) names.each do |name| index.delete(name) end self end |
#to_a ⇒ Object
49 50 51 |
# File 'lib/librarian/manifest_set.rb', line 49 def to_a index.values end |
#to_hash ⇒ Object
53 54 55 |
# File 'lib/librarian/manifest_set.rb', line 53 def to_hash index.dup end |