Class: Lono::Seed::Base

Inherits:
AbstractBase show all
Extended by:
Memoist
Includes:
AwsServices, ServiceRole, Thor::Actions, Thor::Base
Defined in:
lib/lono/seed/base.rb

Direct Known Subclasses

Configs

Instance Method Summary collapse

Methods included from ServiceRole

#create_service_linked_role

Methods included from AwsServices

#cfn, #ec2, #iam, #s3, #s3_presigner, #s3_resource, #sts

Methods included from AwsServices::Helper

#rollback_complete?, #testing_update?

Methods included from AwsServices::StackSet

#find_stack_set, #stack_set_exists?

Methods included from AwsServices::Stack

#find_stack, #stack_exists?

Methods inherited from AbstractBase

#reinitialize, #template_path

Methods included from Blueprint::Root

#find_blueprint_root, #set_blueprint_root

Constructor Details

#initialize(options = {}) ⇒ Base

Override Thor::Base initialize



24
25
26
# File 'lib/lono/seed/base.rb', line 24

def initialize(options={})
  reinitialize(options)
end

Instance Method Details

#create_param_fileObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/lono/seed/base.rb', line 48

def create_param_file
  @output_template = Lono::Output::Template.new(@blueprint, @template)
  if @output_template.parameters.empty?
    puts "Template has no parameters."
    return
  end

  # Generate by parameter group first
  lines, shown = [], []
  @output_template.parameter_groups.each do |label, parameters|
    lines << "# Parameter Group: #{label}"
    parameters.each do |name|
      lines << parameter_line(name)
      shown << name
    end
    lines << ""
  end if @output_template.parameter_groups

  # Then generate the rest
  @output_template.parameters.each do |name, data|
    lines << parameter_line(name) unless shown.include?(name)
  end

  content = lines.join("\n")
  dest_path = "configs/#{@blueprint}/params/#{Lono.env}.txt" # only support environment level parameters for now
  create_file(dest_path, content) # Thor::Action
end

#create_paramsObject



43
44
45
46
# File 'lib/lono/seed/base.rb', line 43

def create_params
  return unless params
  create_param_file
end

#create_variablesObject



100
101
102
103
104
# File 'lib/lono/seed/base.rb', line 100

def create_variables
  return unless variables
  dest_path = "configs/#{@blueprint}/variables/#{Lono.env}.rb"
  create_file(dest_path, variables) # Thor::Action
end

#description_example(description) ⇒ Object



89
90
91
92
93
94
# File 'lib/lono/seed/base.rb', line 89

def description_example(description)
  return unless description
  md = description.match(/(Example|IE): (.*)/)
  return unless md
  md[2]
end

#finishObject



107
# File 'lib/lono/seed/base.rb', line 107

def finish; end

#generate_templateObject



39
40
41
# File 'lib/lono/seed/base.rb', line 39

def generate_template
  Lono::Template::Generator.new(@options).run
end

#parameter_line(name) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/lono/seed/base.rb', line 76

def parameter_line(name)
  data = @output_template.parameters[name]
  example = description_example(data["Description"])
  if data["Default"].nil?
    line = "#{name}=#{example} # (required)"
  else
    default = data["Default"]
    line = "# #{name}=#{default}"
    line = "#{line} # #{example}" if example
  end
  line
end

#paramsObject



96
97
98
# File 'lib/lono/seed/base.rb', line 96

def params
  true
end

#runObject



30
31
32
33
34
35
36
37
# File 'lib/lono/seed/base.rb', line 30

def run
  generate_template
  setup
  self.destination_root = Dir.pwd # Thor::Actions require destination_root to be set
  create_params
  create_variables
  finish
end

#setupObject



106
# File 'lib/lono/seed/base.rb', line 106

def setup; end

#variablesObject

Meant to be overriden by subclass Return String with contents of variables file.



111
112
113
# File 'lib/lono/seed/base.rb', line 111

def variables
  false
end