Class: Jets::Cfn::Builders::ControllerBuilder

Inherits:
BaseChildBuilder show all
Defined in:
lib/jets/cfn/builders/controller_builder.rb

Instance Method Summary collapse

Methods inherited from BaseChildBuilder

#add_class_iam_policy, #add_common_parameters, #add_function, #add_function_iam_policy, #add_functions, #dependency_outputs, #depends_on_params, #initialize, #template_path

Methods included from Interface

#add_output, #add_outputs, #add_parameter, #add_parameters, #add_resource, #add_resources, #add_template_resource, #build, #post_process_template, #template, #text, #write

Constructor Details

This class inherits a constructor from Jets::Cfn::Builders::BaseChildBuilder

Instance Method Details

#add_api_gateway_parametersObject



16
17
18
19
20
21
22
23
24
# File 'lib/jets/cfn/builders/controller_builder.rb', line 16

def add_api_gateway_parameters
  return if Jets::Router.routes.empty?

  add_parameter("RestApi", Description: "RestApi")
  scoped_routes.each do |route|
    resource = Jets::Resource::ApiGateway::Resource.new(route.path)
    add_parameter(resource.logical_id, Description: resource.desc)
  end
end

#add_routesObject



26
27
28
29
30
31
32
33
# File 'lib/jets/cfn/builders/controller_builder.rb', line 26

def add_routes
  scoped_routes.each_with_index do |route, i|
    method = Jets::Resource::ApiGateway::Method.new(route)
    add_resource(method)
    add_resource(method.permission)
    add_resource(method.cors) if Jets.config.cors
  end
end

#composeObject

compose is an interface method for Interface module



9
10
11
12
13
14
# File 'lib/jets/cfn/builders/controller_builder.rb', line 9

def compose
  add_common_parameters
  add_api_gateway_parameters
  add_functions
  add_routes
end

#scoped_routesObject

routes scoped to this controller template.



36
37
38
39
40
# File 'lib/jets/cfn/builders/controller_builder.rb', line 36

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