Class: Jets::Cfn::Builders::BaseChildBuilder

Inherits:
Object
  • Object
show all
Includes:
Interface
Defined in:
lib/jets/cfn/builders/base_child_builder.rb

Instance Method Summary collapse

Methods included from Interface

#add_description, #add_output, #add_outputs, #add_parameter, #add_parameters, #add_resource, #add_resources, #add_template_resource, #build, #post_process_template, #template, #text, #write

Constructor Details

#initialize(app_class) ⇒ BaseChildBuilder

The app_class is can be a controller, job or anonymous function class. IE: PostsController, HardJob



14
15
16
17
# File 'lib/jets/cfn/builders/base_child_builder.rb', line 14

def initialize(app_class)
  @app_class = app_class
  @template = ActiveSupport::HashWithIndifferentAccess.new(Resources: {})
end

Instance Method Details

#add_class_iam_policyObject



55
56
57
58
59
60
# File 'lib/jets/cfn/builders/base_child_builder.rb', line 55

def add_class_iam_policy
  return unless @app_class.build_class_iam?

  resource = Jets::Resource::Iam::ClassRole.new(@app_class)
  add_resource(resource)
end

#add_common_parametersObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/jets/cfn/builders/base_child_builder.rb', line 24

def add_common_parameters
  common_parameters = Jets::Resource::ChildStack::CommonParameters.common_parameters
  common_parameters.each do |k,_|
    add_parameter(k, Description: k.to_s)
  end

  depends_on_params.each do |output_key, output_value|
    desc = output_value.gsub("!GetAtt ", "") # desc doesnt allow !GetAtt
    add_parameter(output_key, Description: desc)
  end
end

#add_function(task) ⇒ Object



50
51
52
53
# File 'lib/jets/cfn/builders/base_child_builder.rb', line 50

def add_function(task)
  resource = Jets::Resource::Lambda::Function.new(task)
  add_resource(resource)
end

#add_function_iam_policy(task) ⇒ Object



62
63
64
65
66
67
# File 'lib/jets/cfn/builders/base_child_builder.rb', line 62

def add_function_iam_policy(task)
  return unless task.build_function_iam?

  resource = Jets::Resource::Iam::FunctionRole.new(task)
  add_resource(resource)
end

#add_functionsObject



42
43
44
45
46
47
48
# File 'lib/jets/cfn/builders/base_child_builder.rb', line 42

def add_functions
  add_class_iam_policy
  @app_class.tasks.each do |task|
    add_function(task)
    add_function_iam_policy(task)
  end
end

#depends_on_paramsObject



36
37
38
39
40
# File 'lib/jets/cfn/builders/base_child_builder.rb', line 36

def depends_on_params
  return {} unless @app_class.depends_on
  depends = Jets::Stack::Depends.new(@app_class.depends_on)
  depends.params
end

#template_pathObject

template_path is an interface method for Interface module



20
21
22
# File 'lib/jets/cfn/builders/base_child_builder.rb', line 20

def template_path
  Jets::Naming.app_template_path(@app_class)
end