class Vulcano::Main

Public Instance Methods

parse_options() click to toggle source
# File lib/vulcano.rb, line 21
def parse_options
  options = {}

  OptionParser.new do |opts|
    opts.banner = "Usage: vulcano json_path [options]"

    opts.on("-d", "--destination-folder DESTINATION_FOLDER", String, "Destination folder for the generated source") do |destination_folder|
      options[:destination_folder] = destination_folder
    end

    opts.on("-n", "--class-name CLASS_NAME", String, "Name for the generated class (the default name is 'Generated')") do |class_name|
      options[:class_name] = class_name
    end

    opts.on("-p", "--public", "Generates all the objects as public objects") do |is_public|
      options[:public] = is_public
    end

    opts.on("-c", "--use-classes", "Generates classes instead of structs") do |use_classes|
      options[:use_classes] = use_classes
    end
  end.parse!

  return options
end
start() click to toggle source
# File lib/vulcano.rb, line 10
def start
  raise RuntimeError, 'The script has to be called with a JSON path' unless ARGV.length > 0

  options = parse_options()

  json_path = ARGV[0]
  destination_folder = options[:destination_folder].nil? ? "." : options[:destination_folder]
  json = JsonReader.new.read_from_file(json_path)
  CodableGenerator.new.generate_codable_file(json, destination_folder, options, options[:class_name])
end