Sha256: f9cb3f5eddcab7690737d13e1e27aeacb8579975855dad189b76db9756e1d1e9

Contents?: true

Size: 1.32 KB

Versions: 5

Compression:

Stored size: 1.32 KB

Contents

require 'xsd_model'
require 'fileutils'
require 'active_support/all'
require 'scaffold_parser/scaffolders/xsd'

module ScaffoldParser
  def self.scaffold(path, options = {})
    scaffold_to_string(File.read(path), options).each do |path, content|
      complete_path = path.prepend('./tmp/')
      ensure_dir_exists(complete_path, options)

      puts "Writing out #{complete_path}" if options[:verbose]

      File.open(complete_path, 'wb') { |f| f.write content }
    end
  end

  def self.scaffold_to_string(schema, options = {})
    parse_options = { collect_only: [:element,
                                     :complex_type,
                                     :sequence,
                                     :all,
                                     :choice,
                                     :schema,
                                     :include,
                                     :import,
                                     :group,
                                     :extension] }
    doc = XsdModel.parse(schema, parse_options)

    Scaffolders::XSD.call(doc, options, parse_options)
  end

  private

  def self.ensure_dir_exists(path, options)
    dir = path.split('/')[0..-2].join('/')

    unless Dir.exists?(dir)
      FileUtils.mkdir_p(dir)

      puts "#{dir} directory created" if options[:verbose]
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
scaffold_parser-0.10.0 lib/scaffold_parser.rb
scaffold_parser-0.9.1 lib/scaffold_parser.rb
scaffold_parser-0.9.0 lib/scaffold_parser.rb
scaffold_parser-0.8.0 lib/scaffold_parser.rb
scaffold_parser-0.7.0 lib/scaffold_parser.rb