Class: Ossy::CLI::Releases::Generate

Inherits:
Commands::Core
  • Object
show all
Defined in:
lib/ossy/cli/releases/generate.rb

Instance Method Summary collapse

Instance Method Details

#call(config_path:, output_path:, template_path:, data_path: nil) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ossy/cli/releases/generate.rb', line 42

def call(config_path:, output_path:, template_path:, data_path: nil)
  puts "Generating #{output_path} from #{config_path} using #{template_path}"

  ctx_data = YAML.load_file(config_path, permitted_classes: [Date])
  template = Tilt.new(template_path)

  context = Context.new(ctx_data)

  if data_path
    key = File.basename(data_path).gsub(".yml", "")
    data = YAML.load_file(data_path, permitted_classes: [Date])

    context.update(key => OpenStruct.new(data))
  end

  output = template.render(context)

  File.write(output_path, "#{output.strip}\n")
end