Class: Jets::Cfn::TemplateMappers::ChildMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/jets/cfn/template_mappers/child_mapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, s3_bucket) ⇒ ChildMapper

Returns a new instance of ChildMapper.



4
5
6
7
8
# File 'lib/jets/cfn/template_mappers/child_mapper.rb', line 4

def initialize(path, s3_bucket)
  # "#{Jets.build_root}/templates/demo-dev-posts_controller.yml"
  @path = path
  @s3_bucket = s3_bucket
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/jets/cfn/template_mappers/child_mapper.rb', line 3

def path
  @path
end

Instance Method Details

#logical_idObject

Example: PostsController



22
23
24
25
26
27
28
29
# File 'lib/jets/cfn/template_mappers/child_mapper.rb', line 22

def logical_id
  regexp = Regexp.new(".*#{Jets.config.project_namespace}-")
  contoller_name = @path.sub(regexp, '').sub('.yml', '')
  # map the path to a camelized logical_id. Example:
  #   /tmp/jets/demo/templates/demo-dev-2-posts_controller.yml to
  #   PostsController
  contoller_name.underscore.camelize
end

#parametersObject

common parameters to all child stacks



11
12
13
14
15
16
17
18
19
# File 'lib/jets/cfn/template_mappers/child_mapper.rb', line 11

def parameters
  parameters = {
    # YAML.dump converts it to a string
    # !GetAtt Base.Outputs.IamRole => "!GetAtt Base.Outputs.IamRole"
    # But post processing of the template fixes this
    IamRole: "!GetAtt IamRole.Arn",
    S3Bucket: "!Ref S3Bucket",
  }
end

#template_urlObject



31
32
33
34
35
36
37
38
39
# File 'lib/jets/cfn/template_mappers/child_mapper.rb', line 31

def template_url
  # here's where it gets interesting with the bucket. The bucket will
  # need to exist for the child templates.  But wont be created until the stack
  # has been first launched.  We can create the bucket in a separate stack
  # And then grab it and then store it in a cache file.
  basename = File.basename(@path)
  # IE: https://s3.amazonaws.com/[bucket]/jets/cfn-templates/demo-dev-posts_controller.yml"
  "https://s3.amazonaws.com/#{@s3_bucket}/jets/cfn-templates/#{basename}"
end