Class: Jets::Cfn::Resource::Nested::AppClass
- Inherits:
-
Base
- Object
- Base
- Base
- Jets::Cfn::Resource::Nested::AppClass
show all
- Defined in:
- lib/jets/cfn/resource/nested/app_class.rb
Direct Known Subclasses
Shared
Instance Method Summary
collapse
Methods inherited from Base
#template_filename, #template_url
Methods inherited from Base
#attributes, #logical_id, #permission, #properties, #replacements, #replacer, #standarize, #template, truncate_id, #type
#camelize
Constructor Details
#initialize(options = {}) ⇒ AppClass
3
4
5
6
|
# File 'lib/jets/cfn/resource/nested/app_class.rb', line 3
def initialize(options={})
super
@path = options[:path]
end
|
Instance Method Details
#add_stagger_depends_on(stacks) ⇒ Object
For staggering. We’re abusing depends_on to slow down the update rate.
For this type of depends_on, there are no template parameters or outputs. To use the normal depends at we would have to make app classes adhere to what Jets::Stack::Depends requires. This is mainly dependency_outputs and output_keys for each class right now. It would not be that difficult but is not needed. So we create the Jets::Stack::Depends::Item objects directly.
43
44
45
46
47
48
|
# File 'lib/jets/cfn/resource/nested/app_class.rb', line 43
def add_stagger_depends_on(stacks)
stack_names = stacks.map { |s| s.current_app_class.to_s.underscore }
items = stack_names.map { |name| Jets::Stack::Depends::Item.new(name) }
@stagger_depends_on ||= []
@stagger_depends_on += items.flatten
end
|
#all_depends_on ⇒ Object
Always returns an Array, could be empty
31
32
33
34
35
|
# File 'lib/jets/cfn/resource/nested/app_class.rb', line 31
def all_depends_on
depends_on = current_app_class.depends_on || []
stagger_depends_on = @stagger_depends_on || []
depends_on + stagger_depends_on
end
|
#app_logical_id ⇒ Object
map the path to a camelized logical_id. Example:
/tmp/jets/demo/templates/demo-dev-2-posts_controller.yml to
PostsController
110
111
112
113
114
|
# File 'lib/jets/cfn/resource/nested/app_class.rb', line 110
def app_logical_id
regexp = Regexp.new(".*#{Jets::Names.templates_folder}/app-")
controller_name = @path.sub(regexp, '').sub('.yml', '')
controller_name.underscore.camelize
end
|
#authorizer_output(desc) ⇒ Object
76
77
78
79
80
|
# File 'lib/jets/cfn/resource/nested/app_class.rb', line 76
def authorizer_output(desc)
authorizer_stack, authorizer_logical_id = desc.split('.')
"#{authorizer_stack}.Outputs.#{authorizer_logical_id}"
end
|
#controller? ⇒ Boolean
90
91
92
|
# File 'lib/jets/cfn/resource/nested/app_class.rb', line 90
def controller?
@path.include?('_controller.yml')
end
|
#controller_params ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/jets/cfn/resource/nested/app_class.rb', line 57
def controller_params
return {} if Jets::Router.no_routes?
params = {
RestApi: "!GetAtt ApiGateway.Outputs.RestApi",
}
template_path = @path
template = Jets::Cfn::Template.load_file(template_path)
template[:Parameters].each do |p,data|
case p
when /Authorizer$/
params[p] = "!GetAtt #{authorizer_output(data[:Description])}"
end
end
params
end
|
#current_app_class ⇒ Object
98
99
100
101
102
103
104
105
|
# File 'lib/jets/cfn/resource/nested/app_class.rb', line 98
def current_app_class
templates_prefix = "#{Jets::Names.templates_folder}/app-"
@path.sub(templates_prefix, '')
.sub(/\.yml$/,'')
.gsub('-','/')
.camelize
.constantize
end
|
#definition ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/jets/cfn/resource/nested/app_class.rb', line 9
def definition
logical_id = app_logical_id
defintion = {
logical_id => {
Type: "AWS::CloudFormation::Stack",
Properties: {
TemplateURL: template_url,
Parameters: parameters,
}
}
}
defintion[logical_id][:DependsOn] = depends.stack_list if depends
defintion
end
|
#depends ⇒ Object
24
25
26
27
|
# File 'lib/jets/cfn/resource/nested/app_class.rb', line 24
def depends
return if all_depends_on.empty?
Jets::Stack::Depends.new(all_depends_on)
end
|
#job? ⇒ Boolean
94
95
96
|
# File 'lib/jets/cfn/resource/nested/app_class.rb', line 94
def job?
@path.include?('_job.yml')
end
|
#outputs ⇒ Object
82
83
84
85
86
87
88
|
# File 'lib/jets/cfn/resource/nested/app_class.rb', line 82
def outputs
if controller? or job?
{}
else
super
end
end
|
#parameters ⇒ Object
50
51
52
53
54
55
|
# File 'lib/jets/cfn/resource/nested/app_class.rb', line 50
def parameters
params = Jets::Cfn::Params::Common.parameters
params.merge!(controller_params) if controller?
params.merge!(depends.params) if depends
params
end
|