Sha256: 9c5b6f9c76e754f647d16e7b57afb07effb80dbe5891e1899bd24212c358e1e3

Contents?: true

Size: 1.2 KB

Versions: 6

Compression:

Stored size: 1.2 KB

Contents

module ScaffoldParser
  module Scaffolders
    class XSD
      class Parser
        class Stack
          include Singleton

          def initialize
            @stack = []
          end

          def push(value)
            similar_classes = @stack.select { |klass| klass.name.start_with? value.name }

            if similar_classes.any?
              same_structure_class = similar_classes.find do |kl|
                kl.namespace == value.namespace &&
                  kl.methods == value.methods &&
                  kl.inherit_from == value.inherit_from
              end

              if same_structure_class
                same_structure_class
              else
                name_base = value.name
                while @stack.find { |klass| klass.name == value.name }
                  counter ||= 1
                  value.name = "#{name_base}#{counter += 1}"
                end
                @stack.push value
                value
              end
            else
              @stack.push value
              value
            end
          end

          def clear
            @stack.clear
          end

          def to_a
            @stack
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
scaffold_parser-0.10.0 lib/scaffold_parser/scaffolders/xsd/parser/stack.rb
scaffold_parser-0.9.1 lib/scaffold_parser/scaffolders/xsd/parser/stack.rb
scaffold_parser-0.9.0 lib/scaffold_parser/scaffolders/xsd/parser/stack.rb
scaffold_parser-0.8.0 lib/scaffold_parser/scaffolders/xsd/parser/stack.rb
scaffold_parser-0.7.0 lib/scaffold_parser/scaffolders/xsd/parser/stack.rb
scaffold_parser-0.6.0 lib/scaffold_parser/scaffolders/xsd/parser/stack.rb