Class: Jets::Cfn::TemplateMappers::GatewayMethodMapper

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

Instance Method Summary collapse

Constructor Details

#initialize(route) ⇒ GatewayMethodMapper

Returns a new instance of GatewayMethodMapper.



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

def initialize(route)
  @route = route # {to: "posts#index", path: "posts", method: :get}
end

Instance Method Details

#controllerObject



51
52
53
54
# File 'lib/jets/cfn/template_mappers/gateway_method_mapper.rb', line 51

def controller
  controller, action = @route.to.split('#')
  "#{controller}_controller".camelize
end

#controller_action_logical_idObject

Example: PostsControllerIndex



46
47
48
49
# File 'lib/jets/cfn/template_mappers/gateway_method_mapper.rb', line 46

def controller_action_logical_id
  controller, action = @route.to.split('#')
  "#{controller}_controller_#{action}".camelize.gsub('::','')
end

#cors_logical_idObject



29
30
31
# File 'lib/jets/cfn/template_mappers/gateway_method_mapper.rb', line 29

def cors_logical_id
  resource_map.cors_logical_id
end

#gateway_resource_logical_idObject

Example returns:

ApiGatewayResourcePostsIdEdit or
ApiGatewayResourcePostsId or
ApiGatewayResourcePosts


25
26
27
# File 'lib/jets/cfn/template_mappers/gateway_method_mapper.rb', line 25

def gateway_resource_logical_id
  resource_map.logical_id
end

#lambda_function_logical_idObject



37
38
39
# File 'lib/jets/cfn/template_mappers/gateway_method_mapper.rb', line 37

def lambda_function_logical_id
  "#{controller_action_logical_id}LambdaFunction"
end

#logical_idObject



7
8
9
10
11
12
13
# File 'lib/jets/cfn/template_mappers/gateway_method_mapper.rb', line 7

def logical_id
  if @route.homepage?
    "RootPathHomepageGetApiGatewayMethod"
  else
    "#{path_method_id}ApiGatewayMethod"
  end
end

#path_method_idObject



15
16
17
18
19
# File 'lib/jets/cfn/template_mappers/gateway_method_mapper.rb', line 15

def path_method_id
  path = @route.path.gsub(':','_').gsub('/','_').gsub('*','')
  method = @route.method.downcase
  "#{path}_#{method}".camelize
end

#permission_logical_idObject



41
42
43
# File 'lib/jets/cfn/template_mappers/gateway_method_mapper.rb', line 41

def permission_logical_id
  "#{controller_action_logical_id}ApiGatewayPermission"
end

#resource_mapObject



33
34
35
# File 'lib/jets/cfn/template_mappers/gateway_method_mapper.rb', line 33

def resource_map
  @resource_map ||= GatewayResourceMapper.new(@route.path)
end