Sha256: 61b545f049a02e72096afe7a8a945506a4dbe2e7957250f07b131824fbbeece4

Contents?: true

Size: 1.5 KB

Versions: 151

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true

require_relative 'action'
module Bundler::Molinillo
  class DependencyGraph
    # @!visibility private
    # @see DependencyGraph#detach_vertex_named
    class DetachVertexNamed < Action
      # @!group Action

      # (see Action#name)
      def self.action_name
        :add_vertex
      end

      # (see Action#up)
      def up(graph)
        return [] unless @vertex = graph.vertices.delete(name)

        removed_vertices = [@vertex]
        @vertex.outgoing_edges.each do |e|
          v = e.destination
          v.incoming_edges.delete(e)
          if !v.root? && v.incoming_edges.empty?
            removed_vertices.concat graph.detach_vertex_named(v.name)
          end
        end

        @vertex.incoming_edges.each do |e|
          v = e.origin
          v.outgoing_edges.delete(e)
        end

        removed_vertices
      end

      # (see Action#down)
      def down(graph)
        return unless @vertex
        graph.vertices[@vertex.name] = @vertex
        @vertex.outgoing_edges.each do |e|
          e.destination.incoming_edges << e
        end
        @vertex.incoming_edges.each do |e|
          e.origin.outgoing_edges << e
        end
      end

      # @!group DetachVertexNamed

      # @return [String] the name of the vertex to detach
      attr_reader :name

      # Initialize an action to detach a vertex from a dependency graph
      # @param [String] name the name of the vertex to detach
      def initialize(name)
        @name = name
      end
    end
  end
end

Version data entries

151 entries across 151 versions & 4 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/bundler-2.3.5/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb
bundler-2.3.27 lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb
rubygems-update-3.3.27 bundler/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/bundler-2.3.5/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb
rubygems-update-3.2.34 bundler/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb
bundler-2.2.34 lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb
tdiary-5.2.4 vendor/bundle/ruby/3.1.0/gems/bundler-2.3.7/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb
rubygems-update-3.3.26 bundler/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb
bundler-2.3.26 lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb
rubygems-update-3.3.25 bundler/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb
bundler-2.3.25 lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb
rubygems-update-3.3.24 bundler/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb
bundler-2.3.24 lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb
rubygems-update-3.3.23 bundler/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb
bundler-2.3.23 lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb
rubygems-update-3.3.22 bundler/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb
bundler-2.3.22 lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb
rubygems-update-3.3.21 bundler/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb
bundler-2.3.21 lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb
rubygems-update-3.3.20 bundler/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb