Class: Vulcano::Main

Inherits:
Object
  • Object
show all
Defined in:
lib/vulcano.rb

Instance Method Summary collapse

Instance Method Details

#parse_optionsObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 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
  end.parse!

  return options
end

#startObject

Raises:

  • (RuntimeError)


10
11
12
13
14
15
16
17
18
19
# 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[:class_name])
end