aws-sdk-code-generator 0.1.0.pre → 0.2.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/aws-sdk-code-generator.rb +68 -75
- data/lib/aws-sdk-code-generator/api.rb +130 -0
- data/lib/aws-sdk-code-generator/apply_docs.rb +15 -2
- data/lib/aws-sdk-code-generator/client_constructor.rb +39 -0
- data/lib/aws-sdk-code-generator/client_operation_documentation.rb +268 -0
- data/lib/aws-sdk-code-generator/client_operation_list.rb +148 -0
- data/lib/aws-sdk-code-generator/client_response_structure_example.rb +108 -0
- data/lib/aws-sdk-code-generator/code_builder.rb +146 -133
- data/lib/aws-sdk-code-generator/crosslink.rb +42 -0
- data/lib/aws-sdk-code-generator/docstring.rb +199 -0
- data/lib/aws-sdk-code-generator/error_list.rb +77 -0
- data/lib/aws-sdk-code-generator/errors.rb +2 -0
- data/lib/aws-sdk-code-generator/eventstream_example.rb +220 -0
- data/lib/aws-sdk-code-generator/gem_builder.rb +19 -25
- data/lib/aws-sdk-code-generator/hash_formatter.rb +5 -2
- data/lib/aws-sdk-code-generator/helper.rb +77 -61
- data/lib/aws-sdk-code-generator/plugin_list.rb +146 -0
- data/lib/aws-sdk-code-generator/resource_action.rb +69 -0
- data/lib/aws-sdk-code-generator/resource_action_code.rb +57 -0
- data/lib/aws-sdk-code-generator/resource_association.rb +37 -0
- data/lib/aws-sdk-code-generator/resource_attribute.rb +76 -0
- data/lib/aws-sdk-code-generator/resource_batch_action.rb +56 -0
- data/lib/aws-sdk-code-generator/resource_batch_action_code.rb +136 -0
- data/lib/aws-sdk-code-generator/resource_batch_action_documentation.rb +108 -0
- data/lib/aws-sdk-code-generator/resource_batch_builder.rb +212 -0
- data/lib/aws-sdk-code-generator/resource_builder.rb +48 -0
- data/lib/aws-sdk-code-generator/resource_client_request.rb +62 -0
- data/lib/aws-sdk-code-generator/resource_client_request_documentation.rb +81 -0
- data/lib/aws-sdk-code-generator/resource_client_request_params.rb +86 -0
- data/lib/aws-sdk-code-generator/resource_data_method.rb +60 -0
- data/lib/aws-sdk-code-generator/resource_has_association.rb +117 -0
- data/lib/aws-sdk-code-generator/resource_has_many_association.rb +52 -0
- data/lib/aws-sdk-code-generator/resource_has_many_association_code.rb +76 -0
- data/lib/aws-sdk-code-generator/resource_identifier.rb +44 -0
- data/lib/aws-sdk-code-generator/resource_identifiers_method.rb +29 -0
- data/lib/aws-sdk-code-generator/resource_load_method.rb +68 -0
- data/lib/aws-sdk-code-generator/resource_method.rb +22 -0
- data/lib/aws-sdk-code-generator/resource_skip_params.rb +36 -0
- data/lib/aws-sdk-code-generator/resource_value_source.rb +68 -0
- data/lib/aws-sdk-code-generator/resource_waiter.rb +80 -0
- data/lib/aws-sdk-code-generator/service.rb +30 -7
- data/lib/aws-sdk-code-generator/shared_example.rb +131 -0
- data/lib/aws-sdk-code-generator/syntax_example.rb +60 -0
- data/lib/aws-sdk-code-generator/syntax_example_hash.rb +174 -0
- data/lib/aws-sdk-code-generator/underscore.rb +10 -5
- data/lib/aws-sdk-code-generator/view.rb +33 -0
- data/lib/aws-sdk-code-generator/views.rb +2 -0
- data/lib/aws-sdk-code-generator/views/apig_endpoint_class.rb +25 -0
- data/lib/aws-sdk-code-generator/views/apig_readme.rb +32 -0
- data/lib/aws-sdk-code-generator/views/async_client_class.rb +68 -0
- data/lib/aws-sdk-code-generator/views/authorizer_class.rb +17 -0
- data/lib/aws-sdk-code-generator/views/client_api_module.rb +583 -0
- data/lib/aws-sdk-code-generator/views/client_class.rb +93 -0
- data/lib/aws-sdk-code-generator/views/docstring.rb +27 -0
- data/lib/aws-sdk-code-generator/views/errors_module.rb +32 -0
- data/lib/aws-sdk-code-generator/views/event_streams_module.rb +149 -0
- data/lib/aws-sdk-code-generator/views/features/env.rb +9 -0
- data/lib/aws-sdk-code-generator/views/features/smoke.rb +51 -0
- data/lib/aws-sdk-code-generator/views/features/smoke_step_definitions.rb +26 -0
- data/lib/aws-sdk-code-generator/views/features/step_definitions.rb +2 -0
- data/lib/aws-sdk-code-generator/views/gemspec.rb +39 -5
- data/lib/aws-sdk-code-generator/views/resource_class.rb +122 -0
- data/lib/aws-sdk-code-generator/views/root_resource_class.rb +58 -0
- data/lib/aws-sdk-code-generator/views/service_module.rb +30 -14
- data/lib/aws-sdk-code-generator/views/spec/spec_helper.rb +9 -0
- data/lib/aws-sdk-code-generator/views/types_module.rb +294 -0
- data/lib/aws-sdk-code-generator/views/version.rb +2 -0
- data/lib/aws-sdk-code-generator/views/waiters_module.rb +37 -0
- data/lib/aws-sdk-code-generator/waiter.rb +95 -0
- data/lib/aws-sdk-code-generator/yard_option_tag.rb +43 -0
- metadata +61 -68
- data/lib/aws-sdk-code-generator/dsl/access_control_statement.rb +0 -23
- data/lib/aws-sdk-code-generator/dsl/attribute_accessor.rb +0 -43
- data/lib/aws-sdk-code-generator/dsl/attribute_reader.rb +0 -11
- data/lib/aws-sdk-code-generator/dsl/attribute_writer.rb +0 -11
- data/lib/aws-sdk-code-generator/dsl/autoload_statement.rb +0 -15
- data/lib/aws-sdk-code-generator/dsl/block_param.rb +0 -11
- data/lib/aws-sdk-code-generator/dsl/class.rb +0 -27
- data/lib/aws-sdk-code-generator/dsl/code_literal.rb +0 -66
- data/lib/aws-sdk-code-generator/dsl/code_object.rb +0 -33
- data/lib/aws-sdk-code-generator/dsl/docstring.rb +0 -36
- data/lib/aws-sdk-code-generator/dsl/eigenclass.rb +0 -15
- data/lib/aws-sdk-code-generator/dsl/extend_statement.rb +0 -12
- data/lib/aws-sdk-code-generator/dsl/formatter.rb +0 -25
- data/lib/aws-sdk-code-generator/dsl/include_statement.rb +0 -17
- data/lib/aws-sdk-code-generator/dsl/main.rb +0 -105
- data/lib/aws-sdk-code-generator/dsl/method.rb +0 -108
- data/lib/aws-sdk-code-generator/dsl/module.rb +0 -167
- data/lib/aws-sdk-code-generator/dsl/option_tag.rb +0 -36
- data/lib/aws-sdk-code-generator/dsl/param.rb +0 -43
- data/lib/aws-sdk-code-generator/dsl/param_list.rb +0 -38
- data/lib/aws-sdk-code-generator/dsl/return_tag.rb +0 -19
- data/lib/aws-sdk-code-generator/dsl/tag_default.rb +0 -20
- data/lib/aws-sdk-code-generator/dsl/tag_docstring.rb +0 -27
- data/lib/aws-sdk-code-generator/dsl/tag_type.rb +0 -18
- data/lib/aws-sdk-code-generator/generators/client_api_module.rb +0 -334
- data/lib/aws-sdk-code-generator/generators/client_class.rb +0 -389
- data/lib/aws-sdk-code-generator/generators/client_operation_documentation.rb +0 -166
- data/lib/aws-sdk-code-generator/generators/errors_module.rb +0 -25
- data/lib/aws-sdk-code-generator/generators/resource/action.rb +0 -88
- data/lib/aws-sdk-code-generator/generators/resource/batch_builder.rb +0 -211
- data/lib/aws-sdk-code-generator/generators/resource/builder.rb +0 -50
- data/lib/aws-sdk-code-generator/generators/resource/client_getter.rb +0 -15
- data/lib/aws-sdk-code-generator/generators/resource/client_request.rb +0 -49
- data/lib/aws-sdk-code-generator/generators/resource/client_request_docs.rb +0 -97
- data/lib/aws-sdk-code-generator/generators/resource/client_request_params.rb +0 -88
- data/lib/aws-sdk-code-generator/generators/resource/collection_class.rb +0 -180
- data/lib/aws-sdk-code-generator/generators/resource/data_attribute_getter.rb +0 -24
- data/lib/aws-sdk-code-generator/generators/resource/data_loaded_method.rb +0 -18
- data/lib/aws-sdk-code-generator/generators/resource/data_method.rb +0 -49
- data/lib/aws-sdk-code-generator/generators/resource/exists_method.rb +0 -29
- data/lib/aws-sdk-code-generator/generators/resource/extract_identifier_method.rb +0 -32
- data/lib/aws-sdk-code-generator/generators/resource/has_association.rb +0 -101
- data/lib/aws-sdk-code-generator/generators/resource/has_many_association.rb +0 -108
- data/lib/aws-sdk-code-generator/generators/resource/identifier_getter.rb +0 -26
- data/lib/aws-sdk-code-generator/generators/resource/identifiers_method.rb +0 -28
- data/lib/aws-sdk-code-generator/generators/resource/initialize_method.rb +0 -67
- data/lib/aws-sdk-code-generator/generators/resource/load_method.rb +0 -65
- data/lib/aws-sdk-code-generator/generators/resource/value_source.rb +0 -68
- data/lib/aws-sdk-code-generator/generators/resource/waiter_method.rb +0 -61
- data/lib/aws-sdk-code-generator/generators/resource_class.rb +0 -325
- data/lib/aws-sdk-code-generator/generators/response_structure_example.rb +0 -83
- data/lib/aws-sdk-code-generator/generators/root_resource_class.rb +0 -42
- data/lib/aws-sdk-code-generator/generators/service_documentation.rb +0 -64
- data/lib/aws-sdk-code-generator/generators/shared_example.rb +0 -132
- data/lib/aws-sdk-code-generator/generators/structure_type_class.rb +0 -95
- data/lib/aws-sdk-code-generator/generators/syntax_example.rb +0 -169
- data/lib/aws-sdk-code-generator/generators/types_module.rb +0 -52
- data/lib/aws-sdk-code-generator/generators/waiter_class.rb +0 -62
- data/lib/aws-sdk-code-generator/generators/waiters_module.rb +0 -20
@@ -1,88 +0,0 @@
|
|
1
|
-
module AwsSdkCodeGenerator
|
2
|
-
module Generators
|
3
|
-
module Resource
|
4
|
-
class ClientRequestParams < String
|
5
|
-
|
6
|
-
include Helper
|
7
|
-
|
8
|
-
# @option options [Array] :params ([])
|
9
|
-
def initialize(options = {})
|
10
|
-
@params = options.fetch(:params, nil) || []
|
11
|
-
super(format_params)
|
12
|
-
end
|
13
|
-
|
14
|
-
def simple?
|
15
|
-
@params.all? { |p| p['target'].match(/^\w+$/) }
|
16
|
-
end
|
17
|
-
|
18
|
-
def empty?
|
19
|
-
@params.empty?
|
20
|
-
end
|
21
|
-
|
22
|
-
def size
|
23
|
-
@params.size
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
def format_params
|
29
|
-
hash = {}
|
30
|
-
@params.each do |param|
|
31
|
-
ParamTarget.new(param).apply(hash, ValueSource.new(param))
|
32
|
-
end
|
33
|
-
formatter = HashFormatter.new(wrap:false, inline: @params.count == 1)
|
34
|
-
params = formatter.format(hash)
|
35
|
-
@params.size == 1 ? params.strip : params
|
36
|
-
end
|
37
|
-
|
38
|
-
class ParamTarget
|
39
|
-
|
40
|
-
def initialize(param)
|
41
|
-
@target = param['target']
|
42
|
-
@steps = []
|
43
|
-
@target.scan(/\w+|\[\]|\[\*\]|\[[0-9]+\]/) do |step|
|
44
|
-
case step
|
45
|
-
when /\[\d+\]/ then @steps += [:array, step[1..-2].to_i]
|
46
|
-
when /\[\*\]/ then @steps += [:array, :n]
|
47
|
-
when '[]' then @steps += [:array, -1]
|
48
|
-
else @steps += [:hash, Underscore.underscore(step).to_sym]
|
49
|
-
end
|
50
|
-
end
|
51
|
-
@steps.shift
|
52
|
-
@final = @steps.pop
|
53
|
-
end
|
54
|
-
|
55
|
-
# @return [String] target
|
56
|
-
attr_reader :target
|
57
|
-
|
58
|
-
def apply(hash, value, options = {})
|
59
|
-
resource_index = options.fetch(:resource_index, 0)
|
60
|
-
if @final == -1
|
61
|
-
build_context(hash, resource_index) << value
|
62
|
-
else
|
63
|
-
build_context(hash, resource_index)[@final] = value
|
64
|
-
end
|
65
|
-
hash
|
66
|
-
end
|
67
|
-
|
68
|
-
private
|
69
|
-
|
70
|
-
def build_context(params, n)
|
71
|
-
@steps.each_slice(2).inject(params) do |context, (key, type)|
|
72
|
-
entry = type == :array ? [] : {}
|
73
|
-
if key == -1
|
74
|
-
context << entry
|
75
|
-
entry
|
76
|
-
elsif key == :n
|
77
|
-
context[n] ||= entry
|
78
|
-
else
|
79
|
-
context[key] ||= entry
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
@@ -1,180 +0,0 @@
|
|
1
|
-
module AwsSdkCodeGenerator
|
2
|
-
module Generators
|
3
|
-
module Resource
|
4
|
-
class CollectionClass < Dsl::Class
|
5
|
-
|
6
|
-
include Helper
|
7
|
-
|
8
|
-
# @option options [required, String] :resource_name
|
9
|
-
# @option options [required, Hash] :resource
|
10
|
-
# @option options [required, Hash] :api
|
11
|
-
def initialize(options)
|
12
|
-
@resource_name = options.fetch(:resource_name)
|
13
|
-
@resource = options.fetch(:resource)
|
14
|
-
@variable_name = underscore(@resource_name)
|
15
|
-
@api = options.fetch(:api)
|
16
|
-
super('Collection', extends: 'Aws::Resources::Collection')
|
17
|
-
add(*batch_actions)
|
18
|
-
end
|
19
|
-
|
20
|
-
def apply(mod)
|
21
|
-
mod.class(@resource_name) do |m|
|
22
|
-
m.add(self)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
def batch_actions
|
29
|
-
if @resource['batchActions']
|
30
|
-
actions = []
|
31
|
-
actions << '# @!group Batch Actions'
|
32
|
-
@resource['batchActions'].each do |name, action|
|
33
|
-
actions << Dsl::Method.new(batch_action_name(name, action)) do |m|
|
34
|
-
m.returns('void')
|
35
|
-
m.param('options', default: {})
|
36
|
-
param_hash(action)
|
37
|
-
apply_batch_action_doc(action, m)
|
38
|
-
m.code('batch_enum.each do |batch|')
|
39
|
-
m.code(initialize_params)
|
40
|
-
m.code(apply_params_per_batch)
|
41
|
-
m.code(batch_request(action))
|
42
|
-
m.code('end')
|
43
|
-
m.code(batch_response)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
actions << '# @!endgroup'
|
47
|
-
actions
|
48
|
-
else
|
49
|
-
[]
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def param_hash(action)
|
54
|
-
@batch_obj = {}
|
55
|
-
@per_batch = {}
|
56
|
-
@action_prefix = false
|
57
|
-
action['request']['params'].each do |param|
|
58
|
-
if param['target'].include?('[')
|
59
|
-
parts = param['target'].split('[')
|
60
|
-
pair = parts[0].split('.')
|
61
|
-
if pair.length > 1
|
62
|
-
@action_prefix = pair.first
|
63
|
-
end
|
64
|
-
batch_name = pair.last
|
65
|
-
batch_param = underscore(parts[1].sub(/.*?\./, ''))
|
66
|
-
batch_param = batch_param == "" ? underscore(param['name']) : batch_param
|
67
|
-
(@batch_obj[batch_name] ||= []) << {
|
68
|
-
batch_param.to_sym => underscore(param['name'] || param['path'])
|
69
|
-
}
|
70
|
-
else
|
71
|
-
@per_batch[param['target']] = underscore(param['name'])
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def apply_batch_action_doc(action, method)
|
77
|
-
skip = []
|
78
|
-
if @action_prefix
|
79
|
-
skip << @action_prefix
|
80
|
-
else
|
81
|
-
skip += @per_batch.keys
|
82
|
-
skip += @batch_obj.keys
|
83
|
-
end
|
84
|
-
ClientRequestDocs.new(
|
85
|
-
request: action['request'],
|
86
|
-
api: @api,
|
87
|
-
skip: skip,
|
88
|
-
var_name: @variable_name,
|
89
|
-
returns: nil
|
90
|
-
).apply(method)
|
91
|
-
end
|
92
|
-
|
93
|
-
def initialize_params
|
94
|
-
param_block = []
|
95
|
-
param_block << " params = Aws::Util.copy_hash(options)"
|
96
|
-
param_block << apply_param_hash
|
97
|
-
param_block.join("\n")
|
98
|
-
end
|
99
|
-
|
100
|
-
def apply_param_hash
|
101
|
-
block = []
|
102
|
-
@per_batch.each do |key, value|
|
103
|
-
block << " params[:#{underscore(key)}] = batch[0].#{value}"
|
104
|
-
end
|
105
|
-
if @action_prefix
|
106
|
-
action = underscore(@action_prefix)
|
107
|
-
block << " params[:#{action}] ||= {}"
|
108
|
-
@batch_obj.keys.each do |key|
|
109
|
-
block << " params[:#{action}][:#{underscore(key)}] ||= []"
|
110
|
-
end
|
111
|
-
else
|
112
|
-
@batch_obj.keys.each {|key| block << " params[:#{underscore(key)}] ||= []"}
|
113
|
-
end
|
114
|
-
block.join("\n")
|
115
|
-
end
|
116
|
-
|
117
|
-
def apply_params_per_batch
|
118
|
-
each_batch = []
|
119
|
-
each_batch << " batch.each do |item|"
|
120
|
-
@batch_obj.each do |key, value|
|
121
|
-
hash = {}
|
122
|
-
value.each do |v|
|
123
|
-
param, identifier = v.first
|
124
|
-
hash[param.to_sym] = "item.#{identifier}"
|
125
|
-
end
|
126
|
-
# Construct hash block
|
127
|
-
if @action_prefix
|
128
|
-
each_batch << " params[:#{underscore(@action_prefix)}][:#{underscore(key)}] << {"
|
129
|
-
else
|
130
|
-
each_batch << " params[:#{underscore(key)}] << {"
|
131
|
-
end
|
132
|
-
# hashformatter treats this as inline, need extra indent
|
133
|
-
indent_count = hash.size == 1 ? 3 : 2
|
134
|
-
each_batch << indent_helper(HashFormatter.new(wrap: false).format(hash), indent_count)
|
135
|
-
each_batch << " }"
|
136
|
-
end
|
137
|
-
each_batch << " end"
|
138
|
-
each_batch.join("\n")
|
139
|
-
end
|
140
|
-
|
141
|
-
def batch_request(action)
|
142
|
-
" batch[0].client.#{underscore(action['request']['operation'])}(params)"
|
143
|
-
end
|
144
|
-
|
145
|
-
def batch_response
|
146
|
-
"nil"
|
147
|
-
end
|
148
|
-
|
149
|
-
def indent_helper(lines, count)
|
150
|
-
block = []
|
151
|
-
lines.split("\n").each do |line|
|
152
|
-
next if line.strip == ""
|
153
|
-
block << " " * count + line
|
154
|
-
end
|
155
|
-
block.join("\n")
|
156
|
-
end
|
157
|
-
|
158
|
-
def batch_action_name(name, action)
|
159
|
-
method_name = "batch_" + underscore(name)
|
160
|
-
method_name += '!' if dangerous?(name, action)
|
161
|
-
method_name
|
162
|
-
end
|
163
|
-
|
164
|
-
def dangerous?(name, action)
|
165
|
-
if
|
166
|
-
name.match(/delete/i) ||
|
167
|
-
name.match(/terminate/i) ||
|
168
|
-
action['request']['operation'].match(/delete/i) ||
|
169
|
-
action['request']['operation'].match(/terminate/i)
|
170
|
-
then
|
171
|
-
true
|
172
|
-
else
|
173
|
-
false
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module AwsSdkCodeGenerator
|
2
|
-
module Generators
|
3
|
-
module Resource
|
4
|
-
class DataAttributeGetter < Dsl::Method
|
5
|
-
|
6
|
-
include Helper
|
7
|
-
|
8
|
-
# @option options [required, Hash] :api
|
9
|
-
# @option options [required, String] :member_name
|
10
|
-
# @option options [required, Hash] :member_ref
|
11
|
-
def initialize(options = {})
|
12
|
-
@api = options.fetch(:api)
|
13
|
-
name = underscore(options.fetch(:member_name))
|
14
|
-
member_ref = options.fetch(:member_ref)
|
15
|
-
super(name)
|
16
|
-
docstring(documentation(member_ref))
|
17
|
-
returns(ruby_type(member_ref))
|
18
|
-
code("data.#{name}")
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module AwsSdkCodeGenerator
|
2
|
-
module Generators
|
3
|
-
module Resource
|
4
|
-
class DataLoadedMethod < Dsl::Method
|
5
|
-
|
6
|
-
def initialize
|
7
|
-
super('data_loaded?')
|
8
|
-
returns('Boolean', docstring:<<-DOCSTRING)
|
9
|
-
Returns `true` if this resource is loaded. Accessing attributes or
|
10
|
-
{#data} on an unloaded resource will trigger a call to {#load}.
|
11
|
-
DOCSTRING
|
12
|
-
code('!!@data')
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
module AwsSdkCodeGenerator
|
2
|
-
module Generators
|
3
|
-
module Resource
|
4
|
-
class DataMethod < Dsl::Method
|
5
|
-
|
6
|
-
# @option options [required, String] :resource_name
|
7
|
-
# @option options [required, Hash] :resource
|
8
|
-
def initialize(options = {})
|
9
|
-
@resource_name = options.fetch(:resource_name)
|
10
|
-
resource = options.fetch(:resource)
|
11
|
-
@shape_name = resource['shape']
|
12
|
-
@load = resource['load'] && resource['load']['request']['operation']
|
13
|
-
super('data')
|
14
|
-
if @shape_name
|
15
|
-
returns("Types::#{@shape_name}", docstring:return_docstring)
|
16
|
-
code do |c|
|
17
|
-
c << 'load unless @data'
|
18
|
-
c << '@data'
|
19
|
-
end
|
20
|
-
if !@load
|
21
|
-
docstring(<<-DOCSTRING)
|
22
|
-
@raise [Errors::ResourceNotLoadableError] Raises when {#data_loaded?} is `false`.
|
23
|
-
DOCSTRING
|
24
|
-
end
|
25
|
-
else
|
26
|
-
docstring('@api private')
|
27
|
-
returns('EmptyStructure')
|
28
|
-
code('@data')
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
|
35
|
-
def return_docstring
|
36
|
-
if @load
|
37
|
-
<<-DOCSTRING
|
38
|
-
Returns the data for this {#{@resource_name}}. Calls
|
39
|
-
{Client##{underscore(@load)}} if {#data_loaded?} is `false`.
|
40
|
-
DOCSTRING
|
41
|
-
else
|
42
|
-
"Returns the data for this {#{@resource_name}}."
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module AwsSdkCodeGenerator
|
2
|
-
module Generators
|
3
|
-
module Resource
|
4
|
-
class ExistsMethod < Dsl::Method
|
5
|
-
|
6
|
-
include Helper
|
7
|
-
|
8
|
-
# @option options [required, String] :resource_name
|
9
|
-
def initialize(options)
|
10
|
-
resource_name = options.fetch(:resource_name)
|
11
|
-
super('exists?')
|
12
|
-
param(:options, type: 'Hash', default: {})
|
13
|
-
returns('Boolean', docstring: "Returns `true` if the #{resource_name} exists.")
|
14
|
-
code <<-CODE
|
15
|
-
begin
|
16
|
-
wait_until_exists(options.merge(max_attempts: 1))
|
17
|
-
true
|
18
|
-
rescue Aws::Waiters::Errors::UnexpectedError => e
|
19
|
-
raise e.error
|
20
|
-
rescue Aws::Waiters::Errors::WaiterFailed
|
21
|
-
false
|
22
|
-
end
|
23
|
-
CODE
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module AwsSdkCodeGenerator
|
2
|
-
module Generators
|
3
|
-
module Resource
|
4
|
-
class ExtractIdentifierMethod < Dsl::Method
|
5
|
-
|
6
|
-
include Helper
|
7
|
-
|
8
|
-
# @option options [required, String] :identifier
|
9
|
-
# @option options [required, Integer] :index
|
10
|
-
def initialize(options = {})
|
11
|
-
identifier = options.fetch(:identifier)
|
12
|
-
name = underscore(identifier['name'])
|
13
|
-
type = identifier_type(identifier)
|
14
|
-
super("extract_#{name}", access: :private)
|
15
|
-
param('args')
|
16
|
-
param('options')
|
17
|
-
code(<<-CODE)
|
18
|
-
value = args[#{options.fetch(:index)}] || options.delete(:#{name})
|
19
|
-
case value
|
20
|
-
when #{type} then value
|
21
|
-
when nil then raise ArgumentError, "missing required option :#{name}"
|
22
|
-
else
|
23
|
-
msg = "expected :#{name} to be a #{type}, got \#{value.class}"
|
24
|
-
raise ArgumentError, msg
|
25
|
-
end
|
26
|
-
CODE
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,101 +0,0 @@
|
|
1
|
-
module AwsSdkCodeGenerator
|
2
|
-
module Generators
|
3
|
-
module Resource
|
4
|
-
class HasAssociation < Dsl::Method
|
5
|
-
|
6
|
-
# @option options [required, String] :name
|
7
|
-
# @option options [required, Hash] :has
|
8
|
-
def initialize(options = {})
|
9
|
-
@has = options.fetch(:has)
|
10
|
-
@data_identifiers = data_identifiers
|
11
|
-
@nullable = !@data_identifiers.empty?
|
12
|
-
@plural = plural?
|
13
|
-
super(underscore(options.fetch(:name)))
|
14
|
-
apply_params
|
15
|
-
apply_code
|
16
|
-
returns(return_type)
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def return_type
|
22
|
-
if @plural
|
23
|
-
collection_type
|
24
|
-
elsif @nullable
|
25
|
-
"#{type}, nil"
|
26
|
-
else
|
27
|
-
type
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def apply_params
|
32
|
-
(@has['resource']['identifiers'] || []).each do |identifier|
|
33
|
-
if identifier['source'] == 'input'
|
34
|
-
param(underscore(identifier['target']), type:'String')
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def type
|
40
|
-
@has['resource']['type']
|
41
|
-
end
|
42
|
-
|
43
|
-
def collection_type
|
44
|
-
"#{type}::Collection"
|
45
|
-
end
|
46
|
-
|
47
|
-
def apply_code
|
48
|
-
if @plural
|
49
|
-
code("batch = []")
|
50
|
-
code(BatchBuilder.new(resource: @has['resource']))
|
51
|
-
code("#{collection_type}.new([batch], size: batch.size)")
|
52
|
-
elsif @nullable # singular association
|
53
|
-
code do |c|
|
54
|
-
c << "if #{null_checks}"
|
55
|
-
c.indent do |c2|
|
56
|
-
c2 << builder
|
57
|
-
end
|
58
|
-
c << "else"
|
59
|
-
c << " nil"
|
60
|
-
c << "end"
|
61
|
-
end
|
62
|
-
else
|
63
|
-
code(builder)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def builder
|
68
|
-
Builder.new(resource: @has['resource'], request_made: false)
|
69
|
-
end
|
70
|
-
|
71
|
-
def plural?
|
72
|
-
plural = false
|
73
|
-
r = @has['resource']
|
74
|
-
(r['identifiers'] || []).each do |i|
|
75
|
-
if i['path'] && i['path'].include?('[]')
|
76
|
-
plural = true
|
77
|
-
break
|
78
|
-
end
|
79
|
-
end
|
80
|
-
plural = true if r['data'] && r['data'].include?('[]')
|
81
|
-
plural
|
82
|
-
end
|
83
|
-
|
84
|
-
def data_identifiers
|
85
|
-
identifiers = []
|
86
|
-
(@has['resource']['identifiers'] || []).each do |i|
|
87
|
-
identifiers << i if i['source'] == 'data'
|
88
|
-
end
|
89
|
-
identifiers
|
90
|
-
end
|
91
|
-
|
92
|
-
def null_checks
|
93
|
-
@data_identifiers.map do |i|
|
94
|
-
ValueSource.new(i)
|
95
|
-
end.join(' && ')
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|