Class: Jets::Resource::ChildStack::Shared

Inherits:
AppClass show all
Includes:
CommonParameters
Defined in:
lib/jets/resource/child_stack/shared.rb

Instance Method Summary collapse

Methods included from CommonParameters

#common_parameters

Methods inherited from AppClass

#add_stagger_depends_on, #all_depends_on, #api_resource_page, #app_logical_id, #authorizer_output, common_parameters, #controller?, #controller_params, #current_app_class, #depends, #job?, #outputs, #parameters, #scoped_routes

Methods inherited from Base

#outputs, #template_url

Methods inherited from Base

#replacements, #resource

Constructor Details

#initialize(s3_bucket, options = {}) ⇒ Shared

Returns a new instance of Shared.



10
11
12
13
# File 'lib/jets/resource/child_stack/shared.rb', line 10

def initialize(s3_bucket, options={})
  super
  @path = options[:path]
end

Instance Method Details

#child_propertiesObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/jets/resource/child_stack/shared.rb', line 27

def child_properties
  props = {
    template_url: template_url,
  }

  props[:parameters] = common_parameters # common child parameters
  # add depends on parameters
  depends_on.each do |dependency|
    dependency_outputs(dependency).each do |output|
      dependency_class = dependency.to_s.camelize
      props[:parameters][output] = "!GetAtt #{dependency_class}.Outputs.#{output}"
    end
  end if depends_on

  props
end

#current_shared_classObject

IE: app/resource.rb => Resource Returns Resource class object in the example



65
66
67
68
69
70
71
72
# File 'lib/jets/resource/child_stack/shared.rb', line 65

def current_shared_class
  templates_prefix = "#{Jets::Naming.template_path_prefix}-shared-"
  @path.sub(templates_prefix, '')
    .sub(/\.yml$/,'')
    .gsub('-','/')
    .camelize
    .constantize # returns actual class
end

#definitionObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/jets/resource/child_stack/shared.rb', line 15

def definition
  logical_id = shared_logical_id
  definition = {
    logical_id => {
      type: "AWS::CloudFormation::Stack",
      properties: child_properties
    }
  }
  definition[logical_id][:depends_on] = depends_on if depends_on
  definition
end

#dependency_outputs(dependency) ⇒ Object

Returns output keys associated with the stack. They are the resource logical ids.



45
46
47
# File 'lib/jets/resource/child_stack/shared.rb', line 45

def dependency_outputs(dependency)
  dependency.to_s.camelize.constantize.output_keys
end

#depends_onObject



49
50
51
52
# File 'lib/jets/resource/child_stack/shared.rb', line 49

def depends_on
  return unless current_shared_class.depends_on
  current_shared_class.depends_on.map { |x| x.to_s.camelize }
end

#resources?Boolean

Tells us if there are any resources defined in the shared class.

Returns: Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/jets/resource/child_stack/shared.rb', line 77

def resources?
  current_shared_class.build?
end

#shared_logical_idObject

map the path to a camelized logical_id. Example:

/tmp/jets/demo/templates/demo-dev-2-shared-resources.yml to
PostsController


57
58
59
60
61
# File 'lib/jets/resource/child_stack/shared.rb', line 57

def shared_logical_id
  regexp = Regexp.new(".*#{Jets.config.project_namespace}-shared-") # remove the shared
  shared_name = @path.sub(regexp, '').sub('.yml', '')
  shared_name.underscore.camelize
end

#template_filenameObject



81
82
83
# File 'lib/jets/resource/child_stack/shared.rb', line 81

def template_filename
  "#{Jets.config.project_namespace}-shared-#{current_shared_class.to_s.underscore}.yml"
end