class Uppercrust::Generator

Public Class Methods

generate(path, base_only) click to toggle source
# File lib/uppercrust/generator.rb, line 9
def self.generate(path, base_only)
  unless File.readable?(path)
    puts "Cannot read path #{path}"
    return
  end

  files = read_files(path, base_only)
  if files.length > 0
    FileUtils.mkdir_p("output")
    output = []
    files.each do |generate|
      puts "Generate #{generate.file_name}"
      output << generate.generate_files
    end
    output.each do |generated|
      generated.each { |name, contents| File.open(File.join("output", name), "w") { |f| f.write(contents) } }
    end
  end
end
glob_dir_for_json(path) click to toggle source
# File lib/uppercrust/generator.rb, line 40
def self.glob_dir_for_json(path)
  Dir.glob(File.join(File.absolute_path(path), '**', '*.json'))
end
read_files(path, base_only) click to toggle source
# File lib/uppercrust/generator.rb, line 29
def self.read_files(path, base_only)
  files = File.file?(File.absolute_path(path)) ? [File.absolute_path(path)] : glob_dir_for_json(path)

  output = []
  files.each do |json_file|
    data = JSON.parse(File.open(json_file, 'r') { |f| f.read })
    output << Parser.new(json_file, data, base_only)
  end
  output
end