Class: Jets::Cfn::TemplateMappers::ControllerMapper

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

Instance Attribute Summary

Attributes inherited from ChildMapper

#path

Instance Method Summary collapse

Methods inherited from ChildMapper

#initialize, #logical_id, #template_url

Constructor Details

This class inherits a constructor from Jets::Cfn::TemplateMappers::ChildMapper

Instance Method Details

#current_classObject

Example:

1. demo-stag-admin-related_pages_controller.yml
2. admin/posts_controller
3. Admin::PostsController


28
29
30
31
32
33
34
# File 'lib/jets/cfn/template_mappers/controller_mapper.rb', line 28

def current_class
  templates_prefix = "#{Jets::Naming.template_path_prefix}-"
  @path.sub(templates_prefix, '')
    .sub(/\.yml$/,'')
    .gsub('-','/')
    .classify
end

#parametersObject

Parameters that are common to all controller stacks



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/jets/cfn/template_mappers/controller_mapper.rb', line 4

def parameters
  parameters = super
  return parameters if Jets::Router.routes.empty?

  # Add the API Gateway parameters
  parameters[:RestApi] = "!GetAtt ApiGateway.Outputs.RestApi"
  scoped_routes.each do |route|
    map = GatewayResourceMapper.new(route.path)
    parameters[map.logical_id] = "!GetAtt ApiGateway.Outputs.#{map.logical_id}"
  end

  parameters
end

#scoped_routesObject



18
19
20
21
22
# File 'lib/jets/cfn/template_mappers/controller_mapper.rb', line 18

def scoped_routes
  @routes ||= Jets::Router.routes.select do |route|
    route.controller_name == current_class
  end
end