Sha256: 78b2282bdf982ff1aaf10e2db2e239c68bea14574e1270e830bf12c8afa3843a

Contents?: true

Size: 1.08 KB

Versions: 4

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

require 'tsort'

module Watir
  module Generator
    class Base
      class IDLSorter
        include TSort

        def initialize(interfaces)
          @interfaces = {}

          interfaces.each do |interface|
            @interfaces[interface.name] ||= []
            interface.inherits.each do |inherit|
              (@interfaces[inherit.name] ||= []) << interface.name
            end
          end
        end

        def print
          @visited = []
          sort.each { |node| print_node(node) }
        end

        def sort
          tsort.reverse
        end

        def tsort_each_node(&blk)
          @interfaces.each_key(&blk)
        end

        def tsort_each_child(node, &blk)
          @interfaces[node].each(&blk)
        end

        private

        def print_node(node, indent = 0)
          return if @visited.include?(node)

          @visited << node
          puts (' ' * indent) + node
          tsort_each_child(node) { |child| print_node(child, indent + 2) }
        end
      end # IDLSorter
    end # Base
  end # Generator
end # Watir

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
watir-7.3.0 lib/watir/generator/base/idl_sorter.rb
watir-7.2.2 lib/watir/generator/base/idl_sorter.rb
watir-7.2.1 lib/watir/generator/base/idl_sorter.rb
watir-7.2.0 lib/watir/generator/base/idl_sorter.rb