Class: Bundler::Molinillo::DependencyGraph (Ruby 2.7.3)
Description: Class : Bundler::Molinillo::DependencyGraph - Ruby 2.7.3

### Home Classes Methods

### In Files

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

### Parent

Object

### Namespace

- CLASS Bundler::Molinillo::DependencyGraph::Action
- CLASS Bundler::Molinillo::DependencyGraph::AddEdgeNoCircular
- CLASS Bundler::Molinillo::DependencyGraph::DeleteEdge
- CLASS Bundler::Molinillo::DependencyGraph::DetachVertexNamed
- CLASS Bundler::Molinillo::DependencyGraph::Log
- CLASS Bundler::Molinillo::DependencyGraph::Tag
- CLASS Bundler::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

- AmbiguousCommandError
- AmbiguousTaskError
- Bundler
- Bundler::APIResponseMismatchError
- Bundler::BuildMetadata
- Bundler::BundlerError
- Bundler::CLI
- Bundler::CLI::Add
- Bundler::CLI::Binstubs
- Bundler::CLI::Cache
- Bundler::CLI::Check
- Bundler::CLI::Clean
- Bundler::CLI::Common
- Bundler::CLI::Config
- Bundler::CLI::Config::Base
- Bundler::CLI::Console
- Bundler::CLI::Doctor
- Bundler::CLI::Exec
- Bundler::CLI::Gem
- Bundler::CLI::Info
- Bundler::CLI::Init
- Bundler::CLI::Inject
- Bundler::CLI::Install
- Bundler::CLI::Issue
- Bundler::CLI::List
- Bundler::CLI::Lock
- Bundler::CLI::Open
- Bundler::CLI::Outdated
- Bundler::CLI::Package
- Bundler::CLI::Platform
- Bundler::CLI::Plugin
- Bundler::CLI::Pristine
- Bundler::CLI::Remove
- Bundler::CLI::Show
- Bundler::CLI::Update
- Bundler::CLI::Viz
- Bundler::CompactIndexClient
- Bundler::CompactIndexClient::Cache
- Bundler::CompactIndexClient::Error
- Bundler::CompactIndexClient::Updater
- Bundler::CompactIndexClient::Updater::MisMatchedChecksumError
- Bundler::ConnectionPool
- Bundler::ConnectionPool::Error
- Bundler::ConnectionPool::PoolShuttingDownError
- Bundler::ConnectionPool::TimedStack
- Bundler::ConnectionPool::Wrapper
- Bundler::CurrentRuby
- Bundler::CyclicDependencyError
- Bundler::Definition
- Bundler::DepProxy
- Bundler::Dependency
- Bundler::Deployment
- Bundler::Deprecate
- Bundler::DeprecatedError
- Bundler::Dsl
- Bundler::Dsl::DSLError
- Bundler::EndpointSpecification
- Bundler::Env
- Bundler::EnvironmentPreserver
- Bundler::FeatureFlag
- Bundler::Fetcher
- Bundler::Fetcher::AuthenticationRequiredError
- Bundler::Fetcher::BadAuthenticationError
- Bundler::Fetcher::Base
- Bundler::Fetcher::CertificateFailureError
- Bundler::Fetcher::CompactIndex
- Bundler::Fetcher::Dependency
- Bundler::Fetcher::Downloader
- Bundler::Fetcher::FallbackError
- Bundler::Fetcher::Index
- Bundler::Fetcher::NetworkDownError
- Bundler::Fetcher::SSLError
- Bundler::Fetcher::TooManyRequestsError
- Bundler::FileUtils
- Bundler::FileUtils::DryRun
- Bundler::FileUtils::NoWrite
- Bundler::FileUtils::StreamUtils_
- Bundler::FileUtils::Verbose
- Bundler::FriendlyErrors
- Bundler::GemHelper
- Bundler::GemHelpers
- Bundler::GemHelpers::PlatformMatch
- Bundler::GemInstaller
- Bundler::GemNotFound
- Bundler::GemRemoteFetcher
- Bundler::GemRequireError
- Bundler::GemVersionPromoter
- Bundler::Gemdeps
- Bundler::GemfileError
- Bundler::GemfileEvalError
- Bundler::GemfileLockNotFound
- Bundler::GemfileNotFound
- Bundler::GemspecError
- Bundler::GenericSystemCallError
- Bundler::GitError
- Bundler::Graph
- Bundler::Graph::GraphVizClient
- Bundler::HTTPError
- Bundler::Index
- Bundler::Injector
- Bundler::InstallError
- Bundler::InstallHookError
- Bundler::Installer
- Bundler::InvalidOption
- Bundler::LazySpecification
- Bundler::LazySpecification::Identifier
- Bundler::LockfileError
- Bundler::LockfileGenerator
- Bundler::LockfileParser
- Bundler::MarshalError
- Bundler::MatchPlatform
- Bundler::MirrorSockets
- Bundler::Molinillo
- Bundler::Molinillo::CircularDependencyError
- Bundler::Molinillo::Compatibility
- Bundler::Molinillo::Delegates
- Bundler::Molinillo::Delegates::ResolutionState
- Bundler::Molinillo::Delegates::SpecificationProvider
- Bundler::Molinillo::DependencyGraph
- Bundler::Molinillo::DependencyGraph::Action
- Bundler::Molinillo::DependencyGraph::AddEdgeNoCircular
- Bundler::Molinillo::DependencyGraph::DeleteEdge
- Bundler::Molinillo::DependencyGraph::DetachVertexNamed
- Bundler::Molinillo::DependencyGraph::Log
- Bundler::Molinillo::DependencyGraph::Tag
- Bundler::Molinillo::DependencyGraph::Vertex
- Bundler::Molinillo::DependencyState
- Bundler::Molinillo::NoSuchDependencyError
- Bundler::Molinillo::PossibilityState
- Bundler::Molinillo::ResolutionState
- Bundler::Molinillo::Resolver
- Bundler::Molinillo::Resolver::Resolution
- Bundler::Molinillo::Resolver::Resolution::Conflict
- Bundler::Molinillo::Resolver::Resolution::PossibilitySet
- Bundler::Molinillo::Resolver::Resolution::UnwindDetails
- Bundler::Molinillo::ResolverError
- Bundler::Molinillo::SpecificationProvider
- Bundler::Molinillo::UI
- Bundler::Molinillo::VersionConflict
- Bundler::NoSpaceOnDeviceError
- Bundler::OperationNotSupportedError
- Bundler::ParallelInstaller
- Bundler::ParallelInstaller::SpecInstallation
- Bundler::PathError
- Bundler::PermissionError
- Bundler::Persistent
- Bundler::Persistent::Net
- Bundler::Persistent::Net::HTTP
- Bundler::Persistent::Net::HTTP::Persistent
- Bundler::Persistent::Net::HTTP::Persistent::Error
- Bundler::PersistentHTTP
- Bundler::Plugin
- Bundler::Plugin::API
- Bundler::Plugin::API::Source
- Bundler::Plugin::DSL
- Bundler::Plugin::DSL::PluginGemfileError
- Bundler::Plugin::Events
- Bundler::Plugin::Index
- Bundler::Plugin::Index::CommandConflict
- Bundler::Plugin::Index::SourceConflict
- Bundler::Plugin::Installer
- Bundler::Plugin::Installer::Git
- Bundler::Plugin::Installer::Rubygems
- Bundler::Plugin::MalformattedPlugin
- Bundler::Plugin::SourceList
- Bundler::Plugin::UndefinedCommandError
- Bundler::Plugin::UnknownSourceError
- Bundler::PluginError
- Bundler::ProcessLock
- Bundler::ProductionError
- Bundler::RemoteSpecification
- Bundler::Resolver
- Bundler::Resolver::SpecGroup
- Bundler::Retry
- Bundler::RubyDsl
- Bundler::RubyGemsGemInstaller
- Bundler::RubyVersion
- Bundler::RubyVersionMismatch
- Bundler::RubygemsIntegration
- Bundler::RubygemsIntegration::Gem
- Bundler::Runtime
- Bundler::SecurityError
- Bundler::Settings
- Bundler::Settings::Mirror
- Bundler::Settings::MirrorConfig
- Bundler::Settings::Mirrors
- Bundler::Settings::TCPSocketProbe
- Bundler::Settings::Validator
- Bundler::Settings::Validator::Rule
- Bundler::SharedHelpers
- Bundler::SimilarityDetector
- Bundler::SocketAddress
- Bundler::Source
- Bundler::Source::Gemspec
- Bundler::Source::Git
- Bundler::Source::Git::GitCommandError
- Bundler::Source::Git::GitNotAllowedError
- Bundler::Source::Git::GitNotInstalledError
- Bundler::Source::Git::GitProxy
- Bundler::Source::Git::MissingGitRevisionError
- Bundler::Source::Metadata
- Bundler::Source::Path
- Bundler::Source::Path::Installer
- Bundler::Source::Rubygems
- Bundler::Source::Rubygems::Remote
- Bundler::SourceList
- Bundler::SpecSet
- Bundler::Standalone
- Bundler::StubSpecification
- Bundler::SudoNotPermittedError
- Bundler::TemporaryResourceError
- Bundler::Thor::Actions
- Bundler::Thor::Actions::CapturableERB
- Bundler::Thor::Actions::ClassMethods
- Bundler::Thor::Base
- Bundler::Thor::Base::ClassMethods
- Bundler::Thor::Command
- Bundler::Thor::CoreExt
- Bundler::Thor::CoreExt::OrderedHash
- Bundler::Thor::DynamicCommand
- Bundler::Thor::DynamicTask
- Bundler::Thor::Group
- Bundler::Thor::HiddenCommand
- Bundler::Thor::HiddenTask
- Bundler::Thor::Invocation
- Bundler::Thor::Invocation::ClassMethods
- Bundler::Thor::LineEditor
- Bundler::Thor::LineEditor::Basic
- Bundler::Thor::LineEditor::Readline
- Bundler::Thor::LineEditor::Readline::PathCompletion
- Bundler::Thor::NestedContext
- Bundler::Thor::RakeCompat
- Bundler::Thor::Shell
- Bundler::Thor::Shell::Basic
- Bundler::Thor::Shell::Color
- Bundler::Thor::Shell::HTML
- Bundler::Thor::Task
- Bundler::Thor::Util
- Bundler::ThreadCreationError
- Bundler::UI
- Bundler::UI::RGProxy
- Bundler::UI::Shell
- Bundler::UI::Silent
- Bundler::URI
- Bundler::URI::BadURIError
- Bundler::URI::Error
- Bundler::URI::Escape
- Bundler::URI::FTP
- Bundler::URI::File
- Bundler::URI::Generic
- Bundler::URI::HTTP
- Bundler::URI::HTTPS
- Bundler::URI::InvalidComponentError
- Bundler::URI::InvalidURIError
- Bundler::URI::LDAP
- Bundler::URI::LDAPS
- Bundler::URI::MailTo
- Bundler::URI::Parser
- Bundler::URI::REGEXP
- Bundler::URI::RFC2396_Parser
- Bundler::URI::RFC2396_REGEXP
- Bundler::URI::RFC2396_REGEXP::PATTERN
- Bundler::URICredentialsFilter
- Bundler::VersionConflict
- Bundler::VersionRanges
- Bundler::VersionRanges::ReqR
- Bundler::VirtualProtocolError
- Bundler::Worker
- Bundler::Worker::WrappedException
- Bundler::YAMLSerializer
- Bundler::YamlSyntaxError
- Error
- Gem
- Gem::Dependency
- Gem::Platform
- Gem::Specification
- InvocationError
- Kernel
- MalformattedArgumentError
- Object
- RequiredArgumentMissingError
- UndefinedCommandError
- UndefinedCommandError::SpellChecker
- UndefinedTaskError
- UnknownArgumentError
- UnknownArgumentError::SpellChecker

No matching classes.

# Bundler::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 bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb, line 56
    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 bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb, line 35
    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 bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb, line 130
    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 bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb, line 146
    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_vertex = vertex_named(parent_name)
        add_edge(parent_vertex, 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 bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb, line 191
    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 bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb, line 161
    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 bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb, line 201
    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 bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb, line 169
    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 bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb, line 16
    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 bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb, line 78
    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 bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb, line 98
    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 bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb, line 71
    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 bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb, line 181
    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 bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb, line 209
    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 bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb, line 64
    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 bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb, line 104
    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 bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb, line 27
    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 bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb, line 175
    def vertex_named(name)
      vertices[name]
    end