Class: Librarian::Dependency
- Inherits:
-
Object
- Object
- Librarian::Dependency
- Defined in:
- lib/librarian/dependency.rb
Defined Under Namespace
Classes: Requirement
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#requirement ⇒ Object
readonly
Returns the value of attribute requirement.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Class Method Summary collapse
-
.merge_dependencies(dependencies) ⇒ Object
merge dependencies with the same name into one with the source of the first one and merged requirements.
-
.remove_duplicate_dependencies(dependencies) ⇒ Object
Avoid duplicated dependencies with different sources or requirements Return [merged dependnecies, duplicates as a map by name].
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #cache_manifests! ⇒ Object
- #consistent_with?(other) ⇒ Boolean
- #hash ⇒ Object
- #inconsistent_with?(other) ⇒ Boolean
-
#initialize(name, requirement, source) ⇒ Dependency
constructor
A new instance of Dependency.
- #manifests ⇒ Object
- #satisfied_by?(manifest) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(name, requirement, source) ⇒ Dependency
Returns a new instance of Dependency.
140 141 142 143 144 145 146 147 148 |
# File 'lib/librarian/dependency.rb', line 140 def initialize(name, requirement, source) assert_name_valid! name self.name = name self.requirement = Requirement.new(requirement) self.source = source @manifests = nil end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
137 138 139 |
# File 'lib/librarian/dependency.rb', line 137 def name @name end |
#requirement ⇒ Object
Returns the value of attribute requirement.
137 138 139 |
# File 'lib/librarian/dependency.rb', line 137 def requirement @requirement end |
#source ⇒ Object
Returns the value of attribute source.
137 138 139 |
# File 'lib/librarian/dependency.rb', line 137 def source @source end |
Class Method Details
.merge_dependencies(dependencies) ⇒ Object
merge dependencies with the same name into one with the source of the first one and merged requirements
191 192 193 194 |
# File 'lib/librarian/dependency.rb', line 191 def merge_dependencies(dependencies) requirement = Dependency::Requirement.new(*dependencies.map{|d| d.requirement}) dependencies.last.class.new(dependencies.last.name, requirement, dependencies.last.source) end |
.remove_duplicate_dependencies(dependencies) ⇒ Object
Avoid duplicated dependencies with different sources or requirements Return [merged dependnecies, duplicates as a map by name]
198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/librarian/dependency.rb', line 198 def remove_duplicate_dependencies(dependencies) uniq = [] duplicated = {} dependencies_by_name = dependencies.group_by{|d| d.name} dependencies_by_name.map do |name, dependencies_same_name| if dependencies_same_name.size > 1 duplicated[name] = dependencies_same_name uniq << merge_dependencies(dependencies_same_name) else uniq << dependencies_same_name.first end end [uniq, duplicated] end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
166 167 168 169 170 171 172 |
# File 'lib/librarian/dependency.rb', line 166 def ==(other) !other.nil? && self.class == other.class && self.name == other.name && self.requirement == other.requirement && self.source == other.source end |
#cache_manifests! ⇒ Object
154 155 156 |
# File 'lib/librarian/dependency.rb', line 154 def cache_manifests! source.manifests(name) end |
#consistent_with?(other) ⇒ Boolean
180 181 182 |
# File 'lib/librarian/dependency.rb', line 180 def consistent_with?(other) name != other.name || requirement.consistent_with?(other.requirement) end |
#hash ⇒ Object
176 177 178 |
# File 'lib/librarian/dependency.rb', line 176 def hash self.to_s.hash end |
#inconsistent_with?(other) ⇒ Boolean
184 185 186 |
# File 'lib/librarian/dependency.rb', line 184 def inconsistent_with?(other) !consistent_with?(other) end |
#manifests ⇒ Object
150 151 152 |
# File 'lib/librarian/dependency.rb', line 150 def manifests @manifests ||= cache_manifests! end |
#satisfied_by?(manifest) ⇒ Boolean
158 159 160 |
# File 'lib/librarian/dependency.rb', line 158 def satisfied_by?(manifest) manifest.satisfies?(self) end |
#to_s ⇒ Object
162 163 164 |
# File 'lib/librarian/dependency.rb', line 162 def to_s "#{name} (#{requirement}) <#{source}>" end |