Class: Jets::Cfn::TemplateMappers::GatewayResourceMapper
- Inherits:
-
Object
- Object
- Jets::Cfn::TemplateMappers::GatewayResourceMapper
- Defined in:
- lib/jets/cfn/template_mappers/gateway_resource_mapper.rb
Instance Method Summary collapse
- #cors_logical_id ⇒ Object
- #desc ⇒ Object
-
#initialize(path) ⇒ GatewayResourceMapper
constructor
A new instance of GatewayResourceMapper.
-
#logical_id ⇒ Object
Returns: “ApiGatewayResourcePostsController”.
- #parent_id ⇒ Object
-
#path ⇒ Object
Modify the path to conform to API Gateway capture expressions.
- #path_part ⇒ Object
- #transform_capture(text) ⇒ Object
Constructor Details
#initialize(path) ⇒ GatewayResourceMapper
Returns a new instance of GatewayResourceMapper.
3 4 5 |
# File 'lib/jets/cfn/template_mappers/gateway_resource_mapper.rb', line 3 def initialize(path) @path = path # Examples: "posts/:id/edit" or "posts" end |
Instance Method Details
#cors_logical_id ⇒ Object
17 18 19 |
# File 'lib/jets/cfn/template_mappers/gateway_resource_mapper.rb', line 17 def cors_logical_id "#{path_logical_id(@path)}CorsApiGatewayResource" end |
#desc ⇒ Object
26 27 28 |
# File 'lib/jets/cfn/template_mappers/gateway_resource_mapper.rb', line 26 def desc path.empty? ? 'Homepage route: /' : "Route for: /#{path}" end |
#logical_id ⇒ Object
Returns: “ApiGatewayResourcePostsController”
8 9 10 11 12 13 14 15 |
# File 'lib/jets/cfn/template_mappers/gateway_resource_mapper.rb', line 8 def logical_id homepage = @path == '' if homepage "RootResourceId" else "#{path_logical_id(@path)}ApiGatewayResource" end end |
#parent_id ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/jets/cfn/template_mappers/gateway_resource_mapper.rb', line 42 def parent_id if @path.include?('/') # posts/:id or posts/:id/edit parent_path = @path.split('/')[0..-2].join('/') parent_logical_id = path_logical_id(parent_path) "!Ref #{parent_logical_id}ApiGatewayResource" else "!GetAtt RestApi.RootResourceId" end end |
#path ⇒ Object
Modify the path to conform to API Gateway capture expressions
22 23 24 |
# File 'lib/jets/cfn/template_mappers/gateway_resource_mapper.rb', line 22 def path @path.split('/').map {|s| transform_capture(s) }.join('/') end |
#path_part ⇒ Object
52 53 54 55 |
# File 'lib/jets/cfn/template_mappers/gateway_resource_mapper.rb', line 52 def path_part last_part = path.split('/').last last_part.split('/').map {|s| transform_capture(s) }.join('/') end |
#transform_capture(text) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/jets/cfn/template_mappers/gateway_resource_mapper.rb', line 30 def transform_capture(text) if text.starts_with?(':') text = text.sub(':','') text = "{#{text}}" # :foo => {foo} end if text.starts_with?('*') text = text.sub('*','') text = "{#{text}+}" # *foo => {foo+} end text end |