Sha256: 6067c882fe4b80bd8164523d1d9ba4d9e01886a13ca68957d2ccb976ae941f4b

Contents?: true

Size: 1.05 KB

Versions: 19

Compression:

Stored size: 1.05 KB

Contents

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

19 entries across 19 versions & 1 rubygems

Version Path
watir-7.1.0 lib/watir/generator/base/idl_sorter.rb
watir-7.0.0 lib/watir/generator/base/idl_sorter.rb
watir-7.0.0.beta5 lib/watir/generator/base/idl_sorter.rb
watir-7.0.0.beta4 lib/watir/generator/base/idl_sorter.rb
watir-7.0.0.beta3 lib/watir/generator/base/idl_sorter.rb
watir-7.0.0.beta2 lib/watir/generator/base/idl_sorter.rb
watir-7.0.0.beta1 lib/watir/generator/base/idl_sorter.rb
watir-6.19.1 lib/watir/generator/base/idl_sorter.rb
watir-6.19.0 lib/watir/generator/base/idl_sorter.rb
watir-6.18.0 lib/watir/generator/base/idl_sorter.rb
watir-6.17.0 lib/watir/generator/base/idl_sorter.rb
watir-6.16.5 lib/watir/generator/base/idl_sorter.rb
watir-6.16.4 lib/watir/generator/base/idl_sorter.rb
watir-6.16.3 lib/watir/generator/base/idl_sorter.rb
watir-6.16.2 lib/watir/generator/base/idl_sorter.rb
watir-6.16.1 lib/watir/generator/base/idl_sorter.rb
watir-6.16.0 lib/watir/generator/base/idl_sorter.rb
watir-6.15.1 lib/watir/generator/base/idl_sorter.rb
watir-6.15.0 lib/watir/generator/base/idl_sorter.rb