Sha256: 2c1754c6c4d74943099fc435a82aa002bd7ba7b94f36759e0ba52d18e4635da3

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

require 'scaffold_parser/scaffolders/xsd/parser'

module ScaffoldParser
  module Scaffolders
    class XSD
      def self.call(doc, options, already_scaffolded_subelements = [])
        self.new(doc, options, already_scaffolded_subelements).call
      end

      def initialize(doc, options, already_scaffolded_subelements)
        @doc = doc
        @options = options
        @already_scaffolded_subelements = already_scaffolded_subelements
      end

      def call
        unless Dir.exists?('./tmp/')
          Dir.mkdir('./tmp/')
          puts './tmp/ directory created'
        end

        unscaffolded_subelements.each do |subelement|
          @already_scaffolded_subelements << subelement.to_class_name

          Parser.call(subelement.definition, @options)
          self.class.call(subelement.definition, @options, @already_scaffolded_subelements)
        end
      end

      private

      def unscaffolded_subelements
        all = @doc.submodel_nodes.to_a + @doc.array_nodes.map(&:list_element)

        all
          .reject(&:xs_type?)
          .reject { |node| @already_scaffolded_subelements.include?(node.to_class_name) }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
scaffold_parser-0.2.0 lib/scaffold_parser/scaffolders/xsd.rb