Class: Awspec::Generator::Doc::Type::Base
- Inherits:
-
Object
- Object
- Awspec::Generator::Doc::Type::Base
show all
- Defined in:
- lib/awspec/generator/doc/type/base.rb
Direct Known Subclasses
Account, AccountAttribute, AccountAttributeBase, Acm, Alb, AlbListener, AlbTargetGroup, Ami, Apigateway, AutoscalingGroup, BatchComputeEnvironment, BatchJobDefinition, BatchJobQueue, CloudformationStack, CloudfrontDistribution, Cloudtrail, CloudwatchAlarm, CloudwatchEvent, CloudwatchLogs, Codebuild, Codedeploy, CodedeployDeploymentGroup, CognitoIdentityPool, CognitoUserPool, CustomerGateway, DirectconnectVirtualInterface, DynamodbTable, Ebs, Ec2, EcrRepository, EcsCluster, EcsContainerInstance, EcsService, EcsTaskDefinition, Efs, Eip, Eks, EksNodegroup, Elasticache, ElasticacheCacheParameterGroup, Elasticsearch, ElastictranscoderPipeline, Elb, Emr, Firehose, IamGroup, IamPolicy, IamRole, IamUser, InternetGateway, Kinesis, Kms, Lambda, LaunchConfiguration, LaunchTemplate, ManagedPrefixList, Mq, Msk, NatGateway, NetworkAcl, NetworkInterface, Nlb, NlbListener, NlbTargetGroup, Rds, RdsDbCluster, RdsDbClusterParameterGroup, RdsDbParameterGroup, RdsDbSubnetGroup, RdsGlobalCluster, RdsProxy, Redshift, RedshiftClusterParameterGroup, Route53HostedZone, RouteTable, S3Bucket, Secretsmanager, SecurityGroup, SesIdentity, SnsTopic, Sqs, SsmParameter, Subnet, TransferServer, TransitGateway, Vpc, VpcEndpoints, VpnConnection, VpnGateway, WafWebAcl, WafregionalWebAcl
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
7
8
9
10
|
# File 'lib/awspec/generator/doc/type/base.rb', line 7
def initialize
Awspec::Stub.load type_name.underscore
@type_name = type_name
end
|
Instance Method Details
#collect_matchers ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/awspec/generator/doc/type/base.rb', line 54
def collect_matchers
methods = @type.methods - Awspec::Helper::Finder.instance_methods - Object.methods
methods.select! do |method|
method.to_s.include?('?')
end
methods.map! do |method|
next 'exist' if method.to_s == 'exists?'
next "have_#{Regexp.last_match[1]}" if /\Ahas_(.+)\?\z/ =~ method.to_s
next "be_#{Regexp.last_match[1]}" if /\A(.+)\?\z/ =~ method.to_s
method.to_s
end
end
|
#doc_template ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/awspec/generator/doc/type/base.rb', line 68
def doc_template
<<-'EOF'
## <a name="<%= @type_name.gsub(/ /, '_').underscore %>"><%= @type_name.gsub(/ /, '_').underscore %></a>
<%= @type_name %> resource type.
<%- if @descriptions.include?('first') -%><%= @descriptions['first'] %><%- end -%>
<% @matchers.each do |matcher| %>
### <%= matcher %>
<%- if @descriptions.include?(matcher) -%><%= @descriptions[matcher] %><%- end -%>
<% end %>
<%- unless its.empty? -%>### <%= its.join(', ') %><%- end -%>
<%- if @descriptions.include?('advanced') -%>
### :unlock: Advanced use
<%= @descriptions['advanced'] %><%- end -%>
EOF
end
|
#generate_doc ⇒ Object
rubocop:disable Metrics/MethodLength
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/awspec/generator/doc/type/base.rb', line 17
def generate_doc
@matchers += collect_matchers - @ignore_matchers
@matchers.sort! do |a, b|
ret = sort_num(a) <=> sort_num(b)
next ret if ret != 0
a.casecmp(b)
end
if @ret.respond_to?(:members)
@describes += @ret.members.select do |describe|
if @ret[describe].is_a?(Array)
next true unless @ret[describe].first.is_a?(Array) || @ret[describe].first.is_a?(Hash) || @ret[describe].first.is_a?(Struct) else
next true unless @ret[describe].is_a?(Hash) || @ret[describe].is_a?(Struct)
end
end
end
its = @describes.map do |describe|
"its(:#{describe})"
end
@descriptions = {}
merge_file = "#{File.dirname(__FILE__)}/../../../../../doc/_resource_types/#{type_name.underscore}.md"
if File.exist?(merge_file)
matcher = nil
File.foreach(merge_file) do |line|
if /\A### (.+)\Z/ =~ line
matcher = Regexp.last_match[1]
next
end
@descriptions[matcher] = '' unless @descriptions[matcher]
@descriptions[matcher] += line
end
end
ERB.new(doc_template, nil, '-').result(binding)
end
|
#sort_num(str) ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/awspec/generator/doc/type/base.rb', line 87
def sort_num(str)
case str
when 'exist'
0
when /\Abe_/
1
when /\Ahave_/
2
else
3
end
end
|
#type_name ⇒ Object
12
13
14
|
# File 'lib/awspec/generator/doc/type/base.rb', line 12
def type_name
self.class.to_s.split('::').last
end
|