module ScaffoldParser

Public Class Methods

scaffold(path, options = {}) click to toggle source
# File lib/scaffold_parser.rb, line 7
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
scaffold_to_string(schema, options = {}) click to toggle source
# File lib/scaffold_parser.rb, line 18
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 Class Methods

ensure_dir_exists(path, options) click to toggle source
# File lib/scaffold_parser.rb, line 36
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