Class: Lono::Seed::Base
Instance Method Summary
collapse
#template_param_convention
#cfn, #ec2, #iam, #s3, #s3_presigner, #s3_resource, #sts
#find_stack, #rollback_complete?, #stack_exists?, #testing_update?
#bundler_groups, #find_blueprint_root, #require_bundle_gems, #set_blueprint_root
Constructor Details
#initialize(blueprint, options) ⇒ Base
28
29
30
31
|
# File 'lib/lono/seed/base.rb', line 28
def initialize(blueprint, options)
@blueprint, @options = blueprint, options
@template, @param = template_param_convention(options)
end
|
Instance Method Details
#check_dsl_type! ⇒ Object
94
95
96
97
98
99
100
101
|
# File 'lib/lono/seed/base.rb', line 94
def check_dsl_type!
dsl_type = template_type == 'dsl'
unless dsl_type
puts "Detected template_type: #{template_type}"
puts "lono seed only supports dsl template types currently."
exit 1
end
end
|
#create_param_file(app_template_path) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/lono/seed/base.rb', line 61
def create_param_file(app_template_path)
parameters = parameters(app_template_path)
lines = []
required = required(parameters)
lines << "# Required parameters:" unless required.empty?
required.each do |name, data|
example = description_example(data["Description"])
lines << "#{name}=#{example}"
end
optional = optional(parameters)
lines << "# Optional parameters:" unless optional.empty?
optional.each do |name, data|
value = default_value(data)
lines << "# #{name}=#{value}"
end
if lines.empty?
puts "Template has no parameters."
return
end
content = lines.join("\n") + "\n"
dest_path = "configs/#{@blueprint}/params/#{Lono.env}.txt" create_file(dest_path, content) end
|
#create_params ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/lono/seed/base.rb', line 42
def create_params
return unless params
path = "#{Lono.config.templates_path}/#{@blueprint}.rb"
if File.exist?(path)
create_param_file(path)
end
end
|
#create_variables ⇒ Object
88
89
90
91
92
|
# File 'lib/lono/seed/base.rb', line 88
def create_variables
return unless variables
dest_path = "configs/#{@blueprint}/variables/#{Lono.env}.rb"
create_file(dest_path, variables) end
|
#default_value(data) ⇒ Object
134
135
136
137
138
139
140
141
142
143
|
# File 'lib/lono/seed/base.rb', line 134
def default_value(data)
value = data["Default"]
if value.nil? || value == ''
description_example(data["Description"])
else
value
end
end
|
#description_example(description) ⇒ Object
126
127
128
129
130
131
132
|
# File 'lib/lono/seed/base.rb', line 126
def description_example(description)
default = '...'
return default unless description
md = description.match(/(Example|IE): (.*)/)
return default unless md
md[2]
end
|
#finish ⇒ Object
113
|
# File 'lib/lono/seed/base.rb', line 113
def finish; end
|
#optional(parameters) ⇒ Object
156
157
158
|
# File 'lib/lono/seed/base.rb', line 156
def optional(parameters)
parameters.select { |logical_id, p| !p["Default"].nil? } end
|
#parameters(app_template_path) ⇒ Object
145
146
147
148
149
|
# File 'lib/lono/seed/base.rb', line 145
def parameters(app_template_path)
builder = Lono::Template::Dsl::Builder.new(app_template_path, @blueprint, quiet: false)
template = builder.template
template["Parameters"] || []
end
|
#params ⇒ Object
57
58
59
|
# File 'lib/lono/seed/base.rb', line 57
def params
true
end
|
#required(parameters) ⇒ Object
152
153
154
|
# File 'lib/lono/seed/base.rb', line 152
def required(parameters)
parameters.select { |logical_id, p| p["Default"].nil? } end
|
#run ⇒ Object
33
34
35
36
37
38
39
40
|
# File 'lib/lono/seed/base.rb', line 33
def run
check_dsl_type!
setup
self.destination_root = Dir.pwd create_params
create_variables
finish
end
|
#setup ⇒ Object
112
|
# File 'lib/lono/seed/base.rb', line 112
def setup; end
|
#template_type ⇒ Object
103
104
105
106
107
108
109
110
|
# File 'lib/lono/seed/base.rb', line 103
def template_type
blueprint_root = find_blueprint_root(@blueprint)
meta_config = "#{blueprint_root}/.meta/config.yml"
return false unless File.exist?(meta_config)
meta = YAML.load_file(meta_config)
meta['template_type']
end
|
#variables ⇒ Object
Meant to be overriden by subclass Return String with contents of variables file.
117
118
119
|
# File 'lib/lono/seed/base.rb', line 117
def variables
false
end
|
#write(path, content) ⇒ Object
121
122
123
124
|
# File 'lib/lono/seed/base.rb', line 121
def write(path, content)
FileUtils.mkdir_p(File.dirname(path))
IO.write(path, content)
end
|