Class: Lono::Inspector::Base

Inherits:
Object
  • Object
show all
Includes:
Blueprint::Root
Defined in:
lib/lono/inspector/base.rb

Direct Known Subclasses

Graph, Summary

Instance Method Summary collapse

Methods included from Blueprint::Root

#bundler_groups, #find_blueprint_root, #require_bundle_gems, #set_blueprint_root

Constructor Details

#initialize(blueprint, template, options) ⇒ Base

Returns a new instance of Base.



4
5
6
# File 'lib/lono/inspector/base.rb', line 4

def initialize(blueprint, template, options)
  @blueprint, @template, @options = blueprint, template, options
end

Instance Method Details

#all_templatesObject



26
27
28
29
30
31
# File 'lib/lono/inspector/base.rb', line 26

def all_templates
  templates_path = "#{Lono.config.output_path}/#{@blueprint_name}/templates"
  Dir.glob("#{templates_path}/**").map do |path|
    path.sub("#{templates_path}/", '').sub('.yml','') # template_name
  end
end

#check_template_exists(template_path) ⇒ Object

Check if the template exists and print friendly error message. Exits if it does not exist.



41
42
43
44
45
46
# File 'lib/lono/inspector/base.rb', line 41

def check_template_exists(template_path)
  unless File.exist?(template_path)
    puts "The template #{template_path} does not exist. Are you sure you use the right template name?  The template name does not require the extension.".color(:red)
    exit 1
  end
end

#dataObject



33
34
35
36
37
# File 'lib/lono/inspector/base.rb', line 33

def data
  template_path = "#{Lono.config.output_path}/#{@blueprint_name}/templates/#{@template_name}.yml"
  check_template_exists(template_path)
  YAML.load(IO.read(template_path))
end

#generate_templatesObject



22
23
24
# File 'lib/lono/inspector/base.rb', line 22

def generate_templates
  Lono::Template::Generator.new(@blueprint_name, @options.clone.merge(quiet: false)).run
end

#runObject



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/lono/inspector/base.rb', line 8

def run
  blueprints = Lono::Blueprint::Find.one_or_all(@blueprint)
  blueprints.each do |blueprint|
    @blueprint_name = blueprint

    generate_templates
    set_blueprint_root(blueprint)
    templates = @template ? [@template] : all_templates
    templates.each do |template_name|
      perform(template_name)
    end
  end
end