Class: Gem::Resolver::Molinillo::DependencyGraph (Ruby 2.5.7)
Description: Class : Gem::Resolver::Molinillo::DependencyGraph - Ruby 2.5.7

### Home Classes Methods

### In Files

- rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb
- rubygems/resolver/molinillo/lib/molinillo/dependency_graph/action.rb
- rubygems/resolver/molinillo/lib/molinillo/dependency_graph/add_edge_no_circular.rb
- rubygems/resolver/molinillo/lib/molinillo/dependency_graph/add_vertex.rb
- rubygems/resolver/molinillo/lib/molinillo/dependency_graph/delete_edge.rb
- rubygems/resolver/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb
- rubygems/resolver/molinillo/lib/molinillo/dependency_graph/log.rb
- rubygems/resolver/molinillo/lib/molinillo/dependency_graph/set_payload.rb
- rubygems/resolver/molinillo/lib/molinillo/dependency_graph/tag.rb
- rubygems/resolver/molinillo/lib/molinillo/dependency_graph/vertex.rb

### Parent

Object

### Namespace

- CLASS Gem::Resolver::Molinillo::DependencyGraph::Action
- CLASS Gem::Resolver::Molinillo::DependencyGraph::AddEdgeNoCircular
- CLASS Gem::Resolver::Molinillo::DependencyGraph::DeleteEdge
- CLASS Gem::Resolver::Molinillo::DependencyGraph::DetachVertexNamed
- CLASS Gem::Resolver::Molinillo::DependencyGraph::Log
- CLASS Gem::Resolver::Molinillo::DependencyGraph::Tag
- CLASS Gem::Resolver::Molinillo::DependencyGraph::Vertex

### Methods

- ::new
- ::tsort
- #==
- #add_child_vertex
- #add_edge
- #add_vertex
- #delete_edge
- #detach_vertex_named
- #each
- #initialize_copy
- #inspect
- #rewind_to
- #root_vertex_named
- #set_payload
- #tag
- #to_dot
- #tsort_each_child
- #tsort_each_node
- #vertex_named

### Included Modules

- Enumerable
- TSort

### Class/Module Index

Quicksearch

- Gem::AvailableSet
- Gem::BasicSpecification
- Gem::BundlerVersionFinder
- Gem::Command
- Gem::CommandLineError
- Gem::CommandManager
- Gem::Commands
- Gem::Commands::BuildCommand
- Gem::Commands::CertCommand
- Gem::Commands::CheckCommand
- Gem::Commands::CleanupCommand
- Gem::Commands::ContentsCommand
- Gem::Commands::DependencyCommand
- Gem::Commands::EnvironmentCommand
- Gem::Commands::FetchCommand
- Gem::Commands::GenerateIndexCommand
- Gem::Commands::HelpCommand
- Gem::Commands::InstallCommand
- Gem::Commands::ListCommand
- Gem::Commands::LockCommand
- Gem::Commands::MirrorCommand
- Gem::Commands::OpenCommand
- Gem::Commands::OutdatedCommand
- Gem::Commands::OwnerCommand
- Gem::Commands::PristineCommand
- Gem::Commands::PushCommand
- Gem::Commands::QueryCommand
- Gem::Commands::RdocCommand
- Gem::Commands::SearchCommand
- Gem::Commands::ServerCommand
- Gem::Commands::SetupCommand
- Gem::Commands::SigninCommand
- Gem::Commands::SignoutCommand
- Gem::Commands::SourcesCommand
- Gem::Commands::SpecificationCommand
- Gem::Commands::StaleCommand
- Gem::Commands::UninstallCommand
- Gem::Commands::UnpackCommand
- Gem::Commands::UpdateCommand
- Gem::Commands::WhichCommand
- Gem::Commands::YankCommand
- Gem::ConfigFile
- Gem::ConflictError
- Gem::ConsoleUI
- Gem::DefaultUserInteraction
- Gem::Dependency
- Gem::DependencyError
- Gem::DependencyInstaller
- Gem::DependencyList
- Gem::DependencyRemovalException
- Gem::DependencyResolutionError
- Gem::Deprecate
- Gem::Doctor
- Gem::DocumentError
- Gem::EndOfYAMLException
- Gem::ErrorReason
- Gem::Exception
- Gem::Ext
- Gem::Ext::BuildError
- Gem::Ext::Builder
- Gem::Ext::CmakeBuilder
- Gem::Ext::ConfigureBuilder
- Gem::Ext::ExtConfBuilder
- Gem::Ext::RakeBuilder
- Gem::FakeFetcher
- Gem::FilePermissionError
- Gem::FormatException
- Gem::GemNotFoundException
- Gem::GemNotInHomeException
- Gem::GemRunner
- Gem::GemcutterUtilities
- Gem::ImpossibleDependenciesError
- Gem::Indexer
- Gem::InstallError
- Gem::InstallUpdateOptions
- Gem::Installer
- Gem::Installer::FakePackage
- Gem::InstallerTestCase
- Gem::InvalidSpecificationException
- Gem::Licenses
- Gem::List
- Gem::LoadError
- Gem::LocalRemoteOptions
- Gem::MissingSpecError
- Gem::MissingSpecVersionError
- Gem::MockGemUi
- Gem::MockGemUi::InputEOFError
- Gem::MockGemUi::SystemExitException
- Gem::MockGemUi::TTY
- Gem::MockGemUi::TermError
- Gem::NameTuple
- Gem::NoAliasYAMLTree
- Gem::OperationNotSupportedError
- Gem::Package::DigestIO
- Gem::Package::Error
- Gem::Package::FormatError
- Gem::Package::NonSeekableIO
- Gem::Package::Old
- Gem::Package::PathError
- Gem::Package::TarHeader
- Gem::Package::TarInvalidError
- Gem::Package::TarReader
- Gem::Package::TarReader::Entry
- Gem::Package::TarReader::UnexpectedEOF
- Gem::Package::TarTestCase
- Gem::Package::TarWriter
- Gem::Package::TarWriter::BoundedStream
- Gem::Package::TarWriter::FileOverflow
- Gem::Package::TarWriter::RestrictedStream
- Gem::Package::TooLongFileName
- Gem::PackageTask
- Gem::PathSupport
- Gem::Platform
- Gem::PlatformMismatch
- Gem::RemoteError
- Gem::RemoteFetcher
- Gem::RemoteFetcher::FetchError
- Gem::RemoteFetcher::UnknownHostError
- Gem::RemoteInstallationCancelled
- Gem::RemoteInstallationSkipped
- Gem::RemoteSourceException
- Gem::RequestSet
- Gem::RequestSet::GemDependencyAPI
- Gem::RequestSet::Lockfile
- Gem::RequestSet::Lockfile::ParseError
- Gem::RequestSet::Lockfile::Parser
- Gem::RequestSet::Lockfile::Tokenizer
- Gem::Requirement
- Gem::Requirement::BadRequirementError
- Gem::Resolver
- Gem::Resolver::APISet
- Gem::Resolver::APISpecification
- Gem::Resolver::ActivationRequest
- Gem::Resolver::BestSet
- Gem::Resolver::ComposedSet
- Gem::Resolver::Conflict
- Gem::Resolver::CurrentSet
- Gem::Resolver::DependencyRequest
- Gem::Resolver::GitSet
- Gem::Resolver::GitSpecification
- Gem::Resolver::IndexSet
- Gem::Resolver::IndexSpecification
- Gem::Resolver::InstalledSpecification
- Gem::Resolver::InstallerSet
- Gem::Resolver::LocalSpecification
- Gem::Resolver::LockSet
- Gem::Resolver::LockSpecification
- Gem::Resolver::Molinillo
- Gem::Resolver::Molinillo::CircularDependencyError
- Gem::Resolver::Molinillo::Delegates
- Gem::Resolver::Molinillo::Delegates::ResolutionState
- Gem::Resolver::Molinillo::Delegates::SpecificationProvider
- Gem::Resolver::Molinillo::DependencyGraph
- Gem::Resolver::Molinillo::DependencyGraph::Action
- Gem::Resolver::Molinillo::DependencyGraph::AddEdgeNoCircular
- Gem::Resolver::Molinillo::DependencyGraph::DeleteEdge
- Gem::Resolver::Molinillo::DependencyGraph::DetachVertexNamed
- Gem::Resolver::Molinillo::DependencyGraph::Log
- Gem::Resolver::Molinillo::DependencyGraph::Tag
- Gem::Resolver::Molinillo::DependencyGraph::Vertex
- Gem::Resolver::Molinillo::DependencyState
- Gem::Resolver::Molinillo::NoSuchDependencyError
- Gem::Resolver::Molinillo::PossibilityState
- Gem::Resolver::Molinillo::ResolutionState
- Gem::Resolver::Molinillo::Resolver
- Gem::Resolver::Molinillo::Resolver::Resolution
- Gem::Resolver::Molinillo::ResolverError
- Gem::Resolver::Molinillo::SpecificationProvider
- Gem::Resolver::Molinillo::UI
- Gem::Resolver::Molinillo::VersionConflict
- Gem::Resolver::RequirementList
- Gem::Resolver::Set
- Gem::Resolver::SourceSet
- Gem::Resolver::SpecSpecification
- Gem::Resolver::Specification
- Gem::Resolver::Stats
- Gem::Resolver::VendorSet
- Gem::Resolver::VendorSpecification
- Gem::RubyVersionMismatch
- Gem::RuntimeRequirementNotMetError
- Gem::SafeYAML
- Gem::Security
- Gem::Security::Exception
- Gem::Security::Policy
- Gem::Security::Signer
- Gem::Security::TrustDir
- Gem::SecurityOption
- Gem::Server
- Gem::SilentUI
- Gem::Source
- Gem::Source::Git
- Gem::Source::Installed
- Gem::Source::Local
- Gem::Source::Lock
- Gem::Source::SpecificFile
- Gem::Source::Vendor
- Gem::SourceFetchProblem
- Gem::SourceList
- Gem::SpecFetcher
- Gem::SpecificGemNotFoundException
- Gem::Specification
- Gem::StreamUI
- Gem::StreamUI::SilentDownloadReporter
- Gem::StreamUI::SilentProgressReporter
- Gem::StreamUI::SimpleProgressReporter
- Gem::StreamUI::VerboseDownloadReporter
- Gem::StreamUI::VerboseProgressReporter
- Gem::StubSpecification
- Gem::SystemExitException
- Gem::TestCase
- Gem::TestCase::SpecFetcherSetup
- Gem::TestCase::StaticSet
- Gem::Text
- Gem::Uninstaller
- Gem::UnsatisfiableDependencyError
- Gem::UriFormatter
- Gem::UserInteraction
- Gem::Util
- Gem::Validator
- Gem::VerificationError
- Gem::Version
- Gem::VersionOption
- Kernel
- Object
- TempIO
- YAML::Syck
- YAML::Syck

No matching classes.

# Gem::Resolver::Molinillo::DependencyGraph

A directed acyclic graph that is tuned to hold named dependencies

### Constants

Edge

  A directed edge of a {DependencyGraph} @attr [Vertex] origin The origin of the directed edge @attr [Vertex] destination The destination of the directed edge @attr [Object] requirement The requirement the directed edge represents

### Attributes

log[R]

@return [Log] the op log for this graph

vertices[R]

@return [{String => Vertex}] the vertices of the dependency graph, keyed

    by {Vertex#name}

### Public Class Methods

new() click to toggle source

Initializes an empty dependency graph

                   # File rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb, line 55
    def initialize
      @vertices = {}
      @log = Log.new
    end

tsort(vertices) click to toggle source

Topologically sorts the given vertices. @param [Enumerable<Vertex>] vertices the vertices to be sorted, which must

    all belong to the same graph.

@return [Array<Vertex>] The sorted vertices.

                   # File rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb, line 34
    def self.tsort(vertices)
      TSort.tsort(
        lambda { |b| vertices.each(&b) },
        lambda { |v, &b| (v.successors & vertices).each(&b) }
      )
    end

### Public Instance Methods

==(other) click to toggle source

@return [Boolean] whether the two dependency graphs are equal, determined

    by a recursive traversal of each {#root_vertices} and its
    {Vertex#successors}

                   # File rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb, line 129
    def ==(other)
      return false unless other
      return true if equal?(other)
      vertices.each do |name, vertex|
        other_vertex = other.vertex_named(name)
        return false unless other_vertex
        return false unless vertex.payload == other_vertex.payload
        return false unless other_vertex.successors.to_set == vertex.successors.to_set
      end
    end

add_child_vertex(name, payload, parent_names, requirement) click to toggle source

@param [String] name @param [Object] payload @param [Array<String>] parent_names @param [Object] requirement the requirement that is requiring the child @return [void]

                   # File rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb, line 145
    def add_child_vertex(name, payload, parent_names, requirement)
      root = !parent_names.delete(nil) { true }
      vertex = add_vertex(name, payload, root)
      vertex.explicit_requirements << requirement if root
      parent_names.each do |parent_name|
        parent_node = vertex_named(parent_name)
        add_edge(parent_node, vertex, requirement)
      end
      vertex
    end

add_edge(origin, destination, requirement) click to toggle source

Adds a new {Edge} to the dependency graph @param [Vertex] origin @param [Vertex] destination @param [Object] requirement the requirement that this edge represents @return [Edge] the added edge

                   # File rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb, line 190
    def add_edge(origin, destination, requirement)
      if destination.path_to?(origin)
        raise CircularDependencyError.new([origin, destination])
      end
      add_edge_no_circular(origin, destination, requirement)
    end

add_vertex(name, payload, root = false) click to toggle source

Adds a vertex with the given name, or updates the existing one. @param [String] name @param [Object] payload @return [Vertex] the vertex that was added to `self`

                   # File rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb, line 160
    def add_vertex(name, payload, root = false)
      log.add_vertex(self, name, payload, root)
    end

delete_edge(edge) click to toggle source

Deletes an {Edge} from the dependency graph @param [Edge] edge @return [Void]

                   # File rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb, line 200
    def delete_edge(edge)
      log.delete_edge(self, edge.origin.name, edge.destination.name, edge.requirement)
    end

detach_vertex_named(name) click to toggle source

Detaches the {#vertex_named} `name` {Vertex} from the graph, recursively removing any non-root vertices that were orphaned in the process @param [String] name @return [Array<Vertex>] the vertices which have been detached

                   # File rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb, line 168
    def detach_vertex_named(name)
      log.detach_vertex_named(self, name)
    end

each() click to toggle source

Enumerates through the vertices of the graph. @return [Array<Vertex>] The graph's vertices.

                   # File rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb, line 15
    def each
      return vertices.values.each unless block_given?
      vertices.values.each { |v| yield v }
    end

Also aliased as: tsort_each_node
initialize_copy(other) click to toggle source

Initializes a copy of a {DependencyGraph}, ensuring that all {#vertices} are properly copied. @param [DependencyGraph] other the graph to copy.

                   # File rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb, line 77
    def initialize_copy(other)
      super
      @vertices = {}
      @log = other.log.dup
      traverse = lambda do |new_v, old_v|
        return if new_v.outgoing_edges.size == old_v.outgoing_edges.size
        old_v.outgoing_edges.each do |edge|
          destination = add_vertex(edge.destination.name, edge.destination.payload)
          add_edge_no_circular(new_v, destination, edge.requirement)
          traverse.call(destination, edge.destination)
        end
      end
      other.vertices.each do |name, vertex|
        new_vertex = add_vertex(name, vertex.payload, vertex.root?)
        new_vertex.explicit_requirements.replace(vertex.explicit_requirements)
        traverse.call(new_vertex, vertex)
      end
    end

inspect() click to toggle source

@return [String] a string suitable for debugging

                   # File rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb, line 97
    def inspect
      "#{self.class}:#{vertices.values.inspect}"
    end

rewind_to(tag) click to toggle source

Rewinds the graph to the state tagged as `tag` @param [Object] tag the tag to rewind to @return [Void]

                   # File rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb, line 70
    def rewind_to(tag)
      log.rewind_to(self, tag)
    end

root_vertex_named(name) click to toggle source

@param [String] name @return [Vertex,nil] the root vertex with the given name

                   # File rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb, line 180
    def root_vertex_named(name)
      vertex = vertex_named(name)
      vertex if vertex && vertex.root?
    end

set_payload(name, payload) click to toggle source

Sets the payload of the vertex with the given name @param [String] name the name of the vertex @param [Object] payload the payload @return [Void]

                   # File rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb, line 208
    def set_payload(name, payload)
      log.set_payload(self, name, payload)
    end

tag(tag) click to toggle source

Tags the current state of the dependency as the given tag @param [Object] tag an opaque tag for the current state of the graph @return [Void]

                   # File rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb, line 63
    def tag(tag)
      log.tag(self, tag)
    end

to_dot(options = {}) click to toggle source

@param [Hash] options options for dot output. @return [String] Returns a dot format representation of the graph

                   # File rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb, line 103
    def to_dot(options = {})
      edge_label = options.delete(:edge_label)
      raise ArgumentError, "Unknown options: #{options.keys}" unless options.empty?

      dot_vertices = []
      dot_edges = []
      vertices.each do |n, v|
        dot_vertices << "  #{n} [label=\"{#{n}|#{v.payload}}\"]"
        v.outgoing_edges.each do |e|
          label = edge_label ? edge_label.call(e) : e.requirement
          dot_edges << "  #{e.origin.name} -> #{e.destination.name} [label=#{label.to_s.dump}]"
        end
      end

      dot_vertices.uniq!
      dot_vertices.sort!
      dot_edges.uniq!
      dot_edges.sort!

      dot = dot_vertices.unshift('digraph G {').push('') + dot_edges.push('}')
      dot.join("\n")
    end

tsort_each_child(vertex, &block) click to toggle source

@!visibility private

                   # File rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb, line 26
    def tsort_each_child(vertex, &block)
      vertex.successors.each(&block)
    end

tsort_each_node() click to toggle source

@!visibility private

Alias for: each
vertex_named(name) click to toggle source

@param [String] name @return [Vertex,nil] the vertex with the given name

                   # File rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb, line 174
    def vertex_named(name)
      vertices[name]
    end