Class: Jets::Cfn::Resource::ApiGateway::Resource
- Inherits:
-
Base
- Object
- Base
- Jets::Cfn::Resource::ApiGateway::Resource
show all
- Defined in:
- lib/jets/cfn/resource/api_gateway/resource.rb
Instance Method Summary
collapse
Methods inherited from Base
#attributes, #logical_id, #parameters, #permission, #properties, #replacements, #replacer, #standarize, #template, truncate_id, #type
#camelize
Constructor Details
#initialize(path, internal: false) ⇒ Resource
Returns a new instance of Resource.
3
4
5
6
7
8
|
# File 'lib/jets/cfn/resource/api_gateway/resource.rb', line 3
def initialize(path, internal: false)
@path = path.delete_prefix('/') @internal = internal
end
|
Instance Method Details
#definition ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/jets/cfn/resource/api_gateway/resource.rb', line 10
def definition
{
resource_logical_id => {
Type: "AWS::ApiGateway::Resource",
Properties: {
ParentId: parent_id,
PathPart: path_part,
RestApiId: "!Ref #{RestApi.logical_id(@internal)}",
}
}
}
end
|
#desc ⇒ Object
For parameter description
40
41
42
|
# File 'lib/jets/cfn/resource/api_gateway/resource.rb', line 40
def desc
path.empty? ? 'Homepage route: /' : "Route for: /#{path}"
end
|
#outputs ⇒ Object
23
24
25
26
27
|
# File 'lib/jets/cfn/resource/api_gateway/resource.rb', line 23
def outputs
{
logical_id => "!Ref #{logical_id}",
}
end
|
#parent_id ⇒ Object
54
55
56
|
# File 'lib/jets/cfn/resource/api_gateway/resource.rb', line 54
def parent_id
"!Ref " + parent_path_parameter
end
|
#parent_path_parameter ⇒ Object
44
45
46
47
48
49
50
51
52
|
# File 'lib/jets/cfn/resource/api_gateway/resource.rb', line 44
def parent_path_parameter
if @path.include?('/') parent_path = @path.split('/')[0..-2].join('/')
parent_logical_id = path_logical_id(parent_path)
Jets::Cfn::Resource.truncate_id(parent_logical_id, "ApiResource")
else
"RootResourceId"
end
end
|
#path ⇒ Object
Modify the path to conform to API Gateway capture expressions
64
65
66
|
# File 'lib/jets/cfn/resource/api_gateway/resource.rb', line 64
def path
@path.split('/').map {|s| transform_capture(s) }.join('/')
end
|
#path_part ⇒ Object
58
59
60
61
|
# File 'lib/jets/cfn/resource/api_gateway/resource.rb', line 58
def path_part
last_part = path.split('/').last
last_part.split('/').map {|s| transform_capture(s) }.join('/') if last_part
end
|
#resource_logical_id ⇒ Object
29
30
31
32
33
34
35
36
37
|
# File 'lib/jets/cfn/resource/api_gateway/resource.rb', line 29
def resource_logical_id
if @path == ''
"RootResourceId"
else
Jets::Cfn::Resource.truncate_id(path_logical_id(@path), "ApiResource")
end
end
|
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/jets/cfn/resource/api_gateway/resource.rb', line 68
def transform_capture(text)
if text.starts_with?(':')
text = text.sub(':','')
text = "{#{text}}" end
if text.starts_with?('*')
text = text.sub('*','')
text = "{#{text}+}" end
text
end
|