Class: Lono::Importer::Dsl

Inherits:
Base show all
Defined in:
lib/lono/importer/dsl.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods included from Download

#download_template, #json?, #read_source

Methods inherited from AbstractBase

#initialize, #reinitialize, #template_path

Methods included from Blueprint::Root

#find_blueprint_root, #set_blueprint_root

Constructor Details

This class inherits a constructor from Lono::Importer::Base

Instance Method Details

#final_messageObject



27
28
29
30
31
32
33
34
# File 'lib/lono/importer/dsl.rb', line 27

def final_message
  puts <<~EOL
    #{"="*64}
    Congrats 🎉 You have successfully imported a lono blueprint.

    More info: https://lono.cloud/docs/core/blueprints
  EOL
end

#runObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/lono/importer/dsl.rb', line 3

def run
  tmp_template_path = download_template(@source, @tmp_path)
  template = IO.read(tmp_template_path)

  Lono::Blueprint::New.start([@blueprint, "--import", "--type", "dsl"])

  translate_to_dsl(template)
  create_params(tmp_template_path)
  # Let's not summarize the template in case the Ruby syntax is invalid with the import coder.
  # Add summarize back in later
  # summarize

  final_message
end

#translate_to_dsl(template) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/lono/importer/dsl.rb', line 18

def translate_to_dsl(template)
  coder = Service::Coder.new(template, @options)
  result = coder.translate

  path = "#{Lono.config.templates_path}/#{@template}.rb"
  FileUtils.mkdir_p(File.dirname(path))
  create_file(path, result) # Thor::Action
end