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_output, #add_outputs, #add_parameter, #add_parameters, #add_resource, #add_resources, #add_template_resource, #build, #cook_template, #post_process_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



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

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



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/jets/cfn/builders/base_child_builder.rb', line 29

def add_common_parameters
  common_parameters = Jets::Resource::ChildStack::AppClass.common_parameters
  common_parameters.each do |k,_|
    add_parameter(k, Description: k)
  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



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

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

#add_function_iam_policy(task) ⇒ Object



68
69
70
71
72
73
# File 'lib/jets/cfn/builders/base_child_builder.rb', line 68

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



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

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



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

def depends_on_params
  return {} unless @app_class.depends_on

  depends = Jets::Stack::Depends.new(@app_class.depends_on)
  depends.params
end

#templateObject

template is an interface method



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

def template 
  @template
end

#template_pathObject

template_path is an interface method for Interface module



25
26
27
# File 'lib/jets/cfn/builders/base_child_builder.rb', line 25

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