Class: Bundler::Molinillo::DependencyGraph

### Home Classes Methods

### In Files

- lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb

### Parent

Object

### Namespace

- CLASS Bundler::Molinillo::DependencyGraph::Vertex

### Methods

- ::new
- ::tsort
- #==
- #add_child_vertex
- #add_edge
- #add_root_vertex
- #add_vertex
- #detach_vertex_named
- #each
- #initialize_copy
- #inspect
- #root_vertex_named
- #tsort_each_child
- #tsort_each_node
- #vertex_named

### Included Modules

- Enumerable
- TSort

### Files

- bundle
- bundle-config
- bundle-config.txt
- bundle-exec
- bundle-exec.txt
- bundle-install
- bundle-install.txt
- bundle-package
- bundle-package.txt
- bundle-platform
- bundle-platform.txt
- bundle-update
- bundle-update.txt
- bundle.txt
- gemfile.5.txt
- Executable
- Gemfile

### Class/Module Index

Quicksearch

- Bundler
- Bundler::BundlerError
- Bundler::CLI
- Bundler::CLI::Binstubs
- Bundler::CLI::Cache
- Bundler::CLI::Check
- Bundler::CLI::Clean
- Bundler::CLI::Common
- Bundler::CLI::Config
- Bundler::CLI::Console
- Bundler::CLI::Exec
- Bundler::CLI::Gem
- Bundler::CLI::Init
- Bundler::CLI::Inject
- Bundler::CLI::Install
- Bundler::CLI::Lock
- Bundler::CLI::Open
- Bundler::CLI::Outdated
- Bundler::CLI::Package
- Bundler::CLI::Platform
- Bundler::CLI::Show
- Bundler::CLI::Update
- Bundler::CLI::Viz
- 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::Environment
- Bundler::Fetcher
- Bundler::Fetcher::AuthenticationRequiredError
- Bundler::Fetcher::BadAuthenticationError
- Bundler::Fetcher::Base
- Bundler::Fetcher::CertificateFailureError
- Bundler::Fetcher::Dependency
- Bundler::Fetcher::Downloader
- Bundler::Fetcher::FallbackError
- Bundler::Fetcher::Index
- Bundler::Fetcher::NetworkDownError
- Bundler::Fetcher::SSLError
- Bundler::GemHelper
- Bundler::GemHelpers
- Bundler::GemInstaller
- Bundler::GemNotFound
- Bundler::GemfileError
- Bundler::GemfileLockNotFound
- Bundler::GemfileNotFound
- Bundler::GemspecError
- Bundler::GitError
- Bundler::Graph
- Bundler::Graph::GraphVizClient
- Bundler::HTTPError
- Bundler::Index
- Bundler::Injector
- Bundler::InstallError
- Bundler::InstallHookError
- Bundler::Installer
- Bundler::InvalidOption
- Bundler::LazySpecification
- Bundler::LockfileError
- Bundler::LockfileParser
- Bundler::MarshalError
- Bundler::MatchPlatform
- Bundler::Molinillo
- Bundler::Molinillo::CircularDependencyError
- Bundler::Molinillo::DependencyGraph
- Bundler::Molinillo::DependencyGraph::Vertex
- Bundler::Molinillo::DependencyState
- Bundler::Molinillo::NoSuchDependencyError
- Bundler::Molinillo::PossibilityState
- Bundler::Molinillo::Resolver
- Bundler::Molinillo::Resolver::Resolution
- Bundler::Molinillo::ResolverError
- Bundler::Molinillo::SpecificationProvider
- Bundler::Molinillo::UI
- Bundler::Molinillo::VersionConflict
- Bundler::PathError
- Bundler::ProductionError
- Bundler::RemoteSpecification
- Bundler::Resolver
- Bundler::Resolver::Molinillo
- Bundler::Resolver::Molinillo::VersionConflict
- Bundler::Resolver::SpecGroup
- Bundler::Retry
- Bundler::RubyDsl
- Bundler::RubyVersion
- Bundler::RubyVersionMismatch
- Bundler::RubygemsIntegration
- Bundler::RubygemsIntegration::AlmostModern
- Bundler::RubygemsIntegration::Ancient
- Bundler::RubygemsIntegration::Future
- Bundler::RubygemsIntegration::Gem
- Bundler::RubygemsIntegration::Legacy
- Bundler::RubygemsIntegration::Legacy::Gem::SourceIndex
- Bundler::RubygemsIntegration::Modern
- Bundler::RubygemsIntegration::MoreFuture
- Bundler::RubygemsIntegration::MoreModern
- Bundler::RubygemsIntegration::Transitional
- Bundler::Runtime
- Bundler::SecurityError
- Bundler::Settings
- Bundler::SharedHelpers
- Bundler::SimilarityDetector
- Bundler::Source
- Bundler::Source::Git
- Bundler::Source::Git::GitCommandError
- Bundler::Source::Git::GitNotAllowedError
- Bundler::Source::Git::GitNotInstalledError
- Bundler::Source::Git::GitProxy
- Bundler::Source::Path
- Bundler::Source::Path::Installer
- Bundler::Source::Rubygems
- Bundler::Source::Rubygems::Remote
- Bundler::SourceList
- Bundler::SpecSet
- Bundler::StubSpecification
- Bundler::SystemRubyVersion
- Bundler::Thor
- Bundler::Thor::Actions
- Bundler::Thor::Actions::ClassMethods
- Bundler::Thor::AmbiguousCommandError
- Bundler::Thor::Base
- Bundler::Thor::Base::ClassMethods
- Bundler::Thor::Command
- Bundler::Thor::DynamicCommand
- Bundler::Thor::Error
- Bundler::Thor::Group
- Bundler::Thor::HiddenCommand
- Bundler::Thor::Invocation
- Bundler::Thor::Invocation::ClassMethods
- Bundler::Thor::InvocationError
- Bundler::Thor::LineEditor
- Bundler::Thor::LineEditor::Basic
- Bundler::Thor::LineEditor::Readline
- Bundler::Thor::LineEditor::Readline::PathCompletion
- Bundler::Thor::MalformattedArgumentError
- Bundler::Thor::RakeCompat
- Bundler::Thor::RequiredArgumentMissingError
- Bundler::Thor::Shell
- Bundler::Thor::Shell::Basic
- Bundler::Thor::Shell::Color
- Bundler::Thor::Shell::HTML
- Bundler::Thor::UndefinedCommandError
- Bundler::Thor::UnknownArgumentError
- Bundler::Thor::Util
- Bundler::UI
- Bundler::UI::RGProxy
- Bundler::UI::Shell
- Bundler::UI::Silent
- Bundler::VersionConflict
- Bundler::Worker
- Bundler::Worker::WrappedException
- Gem
- Gem::Dependency
- Gem::Platform
- Gem::Requirement
- Gem::Specification
- Net
- Net::HTTP
- Net::HTTP::Persistent
- Net::HTTP::Persistent::Error
- Net::HTTP::Persistent::SSLReuse
- ParallelInstaller
- ParallelInstaller::SpecInstallation
- Object

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 [Array] requirements The requirements the directed edge represents

### Attributes

edges[R]

@return [Set<Edge>] the edges of the dependency graph

root_vertices[R]

@return [{String => Vertex}] vertices that have no {Vertex#predecessors},

    keyed by by {Vertex#name}

vertices[R]

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

    by {Vertex#name}

### Public Class Methods

new() click to toggle source

    # File lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb, line 49
    def initialize
      @vertices = {}
      @edges = Set.new
      @root_vertices = {}
    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 lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb, line 27
    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 lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb, line 82
    def ==(other)
      root_vertices == other.root_vertices
    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 lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb, line 91
    def add_child_vertex(name, payload, parent_names, requirement)
      is_root = parent_names.include?(nil)
      parent_nodes = parent_names.compact.map { |n| vertex_named(n) }
      vertex = vertex_named(name) || if is_root
                                       add_root_vertex(name, payload)
                                     else
                                       add_vertex(name, payload)
                                     end
      vertex.payload ||= payload
      parent_nodes.each do |parent_node|
        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 lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb, line 151
    def add_edge(origin, destination, requirement)
      if origin == destination || destination.path_to?(origin)
        raise CircularDependencyError.new([origin, destination])
      end
      Edge.new(origin, destination, [requirement]).tap { |e| edges << e }
    end

add_root_vertex(name, payload) click to toggle source

@param [String] name @param [Object] payload @return [Vertex] the vertex that was added to `self`

    # File lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb, line 117
    def add_root_vertex(name, payload)
      add_vertex(name, payload).tap { |v| root_vertices[name] = v }
    end

add_vertex(name, payload) click to toggle source

@param [String] name @param [Object] payload @return [Vertex] the vertex that was added to `self`

    # File lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb, line 109
    def add_vertex(name, payload)
      vertex = vertices[name] ||= Vertex.new(self, name, payload)
      vertex.tap { |v| v.payload = payload }
    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 [void]

    # File lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb, line 125
    def detach_vertex_named(name)
      vertex = vertex_named(name)
      return unless vertex
      successors = vertex.successors
      vertices.delete(name)
      edges.reject! { |e| e.origin == vertex || e.destination == vertex }
      successors.each { |v| detach_vertex_named(v.name) unless root_vertices[v.name] || v.predecessors.any? }
    end

each() click to toggle source

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

    # File lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb, line 11
    def each
      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} have the correct {Vertex#graph} set

    # File lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb, line 57
    def initialize_copy(other)
      super
      @vertices = other.vertices.reduce({}) do |vertices, (name, vertex)|
        vertices.tap do |hash|
          hash[name] = vertex.dup.tap { |v| v.graph = self }
        end
      end
      @root_vertices = Hash[@vertices.select { |n, _v| other.root_vertices[n] }]
      @edges = other.edges.map do |edge|
        Edge.new(
          vertex_named(edge.origin.name),
          vertex_named(edge.destination.name),
          edge.requirements.dup
        )
      end
    end

inspect() click to toggle source

@return [String] a string suitable for debugging

    # File lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb, line 75
    def inspect
      "#{self.class}:#{vertices.values.inspect}"
    end

root_vertex_named(name) click to toggle source

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

    # File lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb, line 142
    def root_vertex_named(name)
      root_vertices[name]
    end

tsort_each_child(vertex, &block) click to toggle source

    # File lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb, line 19
    def tsort_each_child(vertex, &block)
      vertex.successors.each(&block)
    end

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

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

    # File lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb, line 136
    def vertex_named(name)
      vertices[name]
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.