class Librarian::Dependency

Attributes

name[RW]
requirement[RW]
source[RW]

Public Class Methods

merge_dependencies(dependencies) click to toggle source

merge dependencies with the same name into one with the source of the first one and merged requirements

# 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
new(name, requirement, source) click to toggle source
# 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
remove_duplicate_dependencies(dependencies) click to toggle source

Avoid duplicated dependencies with different sources or requirements Return [merged dependnecies, duplicates as a map by name]

# 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

Public Instance Methods

==(other) click to toggle source
# 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
Also aliased as: eql?
cache_manifests!() click to toggle source
# File lib/librarian/dependency.rb, line 154
def cache_manifests!
  source.manifests(name)
end
consistent_with?(other) click to toggle source
# File lib/librarian/dependency.rb, line 180
def consistent_with?(other)
  name != other.name || requirement.consistent_with?(other.requirement)
end
eql?(other)
Alias for: ==
hash() click to toggle source
# File lib/librarian/dependency.rb, line 176
def hash
  self.to_s.hash
end
inconsistent_with?(other) click to toggle source
# File lib/librarian/dependency.rb, line 184
def inconsistent_with?(other)
  !consistent_with?(other)
end
manifests() click to toggle source
# File lib/librarian/dependency.rb, line 150
def manifests
  @manifests ||= cache_manifests!
end
satisfied_by?(manifest) click to toggle source
# File lib/librarian/dependency.rb, line 158
def satisfied_by?(manifest)
  manifest.satisfies?(self)
end
to_s() click to toggle source
# File lib/librarian/dependency.rb, line 162
def to_s
  "#{name} (#{requirement}) <#{source}>"
end

Private Instance Methods

assert_name_valid!(name) click to toggle source
# File lib/librarian/dependency.rb, line 216
def assert_name_valid!(name)
  name =~ /\A\S(?:.*\S)?\z/ and return

  raise ArgumentError, "name (#{name.inspect}) must be sensible"
end