Class: Jets::Cfn::Resource::Nested::Shared
- Defined in:
- lib/jets/cfn/resource/nested/shared.rb
Instance Method Summary collapse
- #child_properties ⇒ Object
-
#current_shared_class ⇒ Object
IE: app/resource.rb => Resource Returns Resource class object in the example.
- #definition ⇒ Object
-
#dependency_outputs(dependency) ⇒ Object
Returns output keys associated with the stack.
- #depends_on ⇒ Object
-
#initialize(options = {}) ⇒ Shared
constructor
A new instance of Shared.
-
#resources? ⇒ Boolean
Tells us if there are any resources defined in the shared class.
-
#shared_logical_id ⇒ Object
map the path to a camelized logical_id.
Methods inherited from AppClass
#add_stagger_depends_on, #all_depends_on, #app_logical_id, #authorizer_output, #controller?, #controller_params, #current_app_class, #depends, #job?, #outputs, #parameters
Methods inherited from Base
#outputs, #template_filename, #template_url
Methods inherited from Base
#attributes, #logical_id, #outputs, #parameters, #permission, #properties, #replacements, #replacer, #standarize, #template, truncate_id, #type
Methods included from Util::Camelize
Constructor Details
#initialize(options = {}) ⇒ Shared
Returns a new instance of Shared.
8 9 10 11 |
# File 'lib/jets/cfn/resource/nested/shared.rb', line 8 def initialize(={}) super @path = [:path] end |
Instance Method Details
#child_properties ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/jets/cfn/resource/nested/shared.rb', line 25 def child_properties props = { TemplateURL: template_url, } props[:Parameters] = Jets::Cfn::Params::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_class ⇒ Object
IE: app/resource.rb => Resource Returns Resource class object in the example
63 64 65 66 67 68 69 70 |
# File 'lib/jets/cfn/resource/nested/shared.rb', line 63 def current_shared_class templates_prefix = "#{Jets::Names.templates_folder}/shared-" @path.sub(templates_prefix, '') .sub(/\.yml$/,'') .gsub('-','/') .camelize .constantize # returns actual class end |
#definition ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/jets/cfn/resource/nested/shared.rb', line 13 def definition logical_id = shared_logical_id definition = { logical_id => { Type: "AWS::CloudFormation::Stack", Properties: child_properties } } definition[logical_id][:DependsOn] = depends_on if depends_on definition end |
#dependency_outputs(dependency) ⇒ Object
Returns output keys associated with the stack. They are the resource logical ids.
43 44 45 |
# File 'lib/jets/cfn/resource/nested/shared.rb', line 43 def dependency_outputs(dependency) dependency.to_s.camelize.constantize.output_keys end |
#depends_on ⇒ Object
47 48 49 50 |
# File 'lib/jets/cfn/resource/nested/shared.rb', line 47 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
75 76 77 |
# File 'lib/jets/cfn/resource/nested/shared.rb', line 75 def resources? current_shared_class.build? end |
#shared_logical_id ⇒ Object
map the path to a camelized logical_id. Example:
/tmp/jets/demo/templates/demo-dev-2-shared-resources.yml to
PostsController
55 56 57 58 59 |
# File 'lib/jets/cfn/resource/nested/shared.rb', line 55 def shared_logical_id regexp = Regexp.new(".*#{Jets::Names.templates_folder}/shared-") # remove the shared shared_name = @path.sub(regexp, '').sub('.yml', '') shared_name.underscore.camelize end |