Class: Jets::Cfn::Builders::ApiResourcesBuilder

Inherits:
Object
  • Object
show all
Includes:
AwsServices, Interface
Defined in:
lib/jets/cfn/builders/api_resources_builder.rb

Instance Method Summary collapse

Methods included from AwsServices

#apigateway, #aws_lambda, #aws_options, #cfn, #dynamodb, #logs, #s3, #s3_resource, #sns, #sqs, #sts

Methods included from AwsServices::StackStatus

#lookup, #stack_exists?, #stack_in_progress?

Methods included from AwsServices::GlobalMemoist

included

Methods included from Interface

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

Constructor Details

#initialize(options = {}, paths = [], page) ⇒ ApiResourcesBuilder

Returns a new instance of ApiResourcesBuilder.



6
7
8
9
# File 'lib/jets/cfn/builders/api_resources_builder.rb', line 6

def initialize(options={}, paths=[], page)
  @options, @paths, @page = options, paths, page
  @template = ActiveSupport::HashWithIndifferentAccess.new(Resources: {})
end

Instance Method Details

#add_gateway_routesObject



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/jets/cfn/builders/api_resources_builder.rb', line 26

def add_gateway_routes
  @paths.each do |path|
    homepage = path == ''
    next if homepage # handled by RootResourceId output already

    resource = Jets::Resource::ApiGateway::Resource.new(path)
    add_resource(resource)
    add_outputs(resource.outputs)

    parent_path = resource.parent_path_parameter
    add_parameter(parent_path) unless part_of_template?(parent_path)
  end
end

#add_rest_api_parameterObject



22
23
24
# File 'lib/jets/cfn/builders/api_resources_builder.rb', line 22

def add_rest_api_parameter
  add_parameter("RestApi", Description: "RestApi")
end

#composeObject

compose is an interface method



12
13
14
15
# File 'lib/jets/cfn/builders/api_resources_builder.rb', line 12

def compose
  add_rest_api_parameter
  add_gateway_routes
end

#part_of_template?(parent_path) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/jets/cfn/builders/api_resources_builder.rb', line 40

def part_of_template?(parent_path)
  @template["Resources"].key?(parent_path)
end

#template_pathObject

template_path is an interface method



18
19
20
# File 'lib/jets/cfn/builders/api_resources_builder.rb', line 18

def template_path
  Jets::Names.api_resources_template_path(@page)
end