Sha256: fd2c9f4c6c0a96d6c61d0df4a55410fbc6a74a0bb858f268852b70121749d1cd

Contents?: true

Size: 983 Bytes

Versions: 49

Compression:

Stored size: 983 Bytes

Contents

require 'tsort'

module Watir
  module Generator
    class Base::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 # Generator
end # Watir

Version data entries

49 entries across 49 versions & 2 rubygems

Version Path
watir-6.13.0 lib/watir/generator/base/idl_sorter.rb
watir-6.12.0 lib/watir/generator/base/idl_sorter.rb
watir-6.11.0 lib/watir/generator/base/idl_sorter.rb
watir-6.11.0.beta2 lib/watir/generator/base/idl_sorter.rb
watir-6.11.0.beta1 lib/watir/generator/base/idl_sorter.rb
watir-6.10.3 lib/watir/generator/base/idl_sorter.rb
watir-6.10.2 lib/watir/generator/base/idl_sorter.rb
watir-6.10.0 lib/watir/generator/base/idl_sorter.rb
watir-6.9.1 lib/watir/generator/base/idl_sorter.rb
watir-6.9.0 lib/watir/generator/base/idl_sorter.rb
watir-6.8.4 lib/watir/generator/base/idl_sorter.rb
watir-6.8.3 lib/watir/generator/base/idl_sorter.rb
watir-6.8.2 lib/watir/generator/base/idl_sorter.rb
watir-6.8.1 lib/watir/generator/base/idl_sorter.rb
watir-6.8.0 lib/watir/generator/base/idl_sorter.rb
watir-6.7.3 lib/watir/generator/base/idl_sorter.rb
watir-6.7.2 lib/watir/generator/base/idl_sorter.rb
watir-6.7.1 lib/watir/generator/base/idl_sorter.rb
watir-6.7.0 lib/watir/generator/base/idl_sorter.rb
watir-6.6.3 lib/watir/generator/base/idl_sorter.rb