Module: Prmd::Generate

Defined in:
lib/prmd/commands/init.rb

Overview

Schema generation

Class Method Summary collapse

Class Method Details

.make_generator(options) ⇒ Prmd::Generator

Creates a default Prmd::Generator using default templates

Returns:


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/prmd/commands/init.rb', line 12

def self.make_generator(options)
  base = Prmd::Template.load_json('init_default.json')
  template_name = options.fetch(:template) do
    abort 'render: Template was not provided'
  end
  if template_name && !template_name.empty?
    template_dir = File.expand_path(template_name)
    # to keep backward compatibility
    template_dir = File.dirname(template_name) unless File.directory?(template_dir)
    template_name = File.basename(template_name)
  else
    template_name = 'init_resource.json.erb'
    template_dir  = ''
  end
  template = Prmd::Template.load_template(template_name, template_dir)
  Prmd::Generator.new(base: base, template: template)
end