aws-sdk-code-generator 0.1.0.pre → 0.2.4.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/api.rb +150 -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 +282 -0
- data/lib/aws-sdk-code-generator/client_operation_list.rb +148 -0
- data/lib/aws-sdk-code-generator/client_response_structure_example.rb +115 -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 +42 -25
- data/lib/aws-sdk-code-generator/hash_formatter.rb +5 -2
- data/lib/aws-sdk-code-generator/helper.rb +86 -119
- data/lib/aws-sdk-code-generator/plugin_list.rb +147 -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/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 +602 -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 +52 -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 +6 -2
- 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 +38 -14
- data/lib/aws-sdk-code-generator/views/spec/spec_helper.rb +9 -0
- data/lib/aws-sdk-code-generator/views/types_module.rb +329 -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/views.rb +2 -0
- data/lib/aws-sdk-code-generator/waiter.rb +95 -0
- data/lib/aws-sdk-code-generator/yard_option_tag.rb +43 -0
- data/lib/aws-sdk-code-generator.rb +68 -75
- data/templates/apig_endpoint_class.mustache +16 -0
- data/templates/apig_readme.mustache +62 -0
- data/templates/async_client_class.mustache +125 -0
- data/templates/authorizer_class.mustache +37 -0
- data/templates/client_api_module.mustache +106 -0
- data/templates/client_class.mustache +295 -0
- data/templates/code.mustache +4 -0
- data/templates/documentation.mustache +4 -0
- data/templates/errors_module.mustache +70 -0
- data/templates/event_streams_module.mustache +76 -0
- data/templates/features/env.mustache +15 -0
- data/templates/features/smoke.mustache +22 -0
- data/templates/features/smoke_step_definitions.mustache +31 -0
- data/templates/features/step_definitions.mustache +13 -0
- data/templates/gemspec.mustache +31 -0
- data/templates/license.txt +202 -0
- data/templates/method.mustache +7 -0
- data/templates/resource_class.mustache +304 -0
- data/templates/root_resource_class.mustache +51 -0
- data/templates/service_module.mustache +58 -0
- data/templates/spec/spec_helper.mustache +15 -0
- data/templates/types_module.mustache +53 -0
- data/templates/version.mustache +1 -0
- data/templates/waiters_module.mustache +112 -0
- metadata +115 -70
- 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,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
|
@@ -1,108 +0,0 @@
|
|
1
|
-
module AwsSdkCodeGenerator
|
2
|
-
module Generators
|
3
|
-
module Resource
|
4
|
-
|
5
|
-
# TODO : build and return collection
|
6
|
-
# TODO : filter @option tags related to pagination
|
7
|
-
# TODO : don't filter @option tags that can be merged, e.g. EC2 Filters
|
8
|
-
class HasManyAssociation < Dsl::Method
|
9
|
-
|
10
|
-
# @option options [required, String] :name
|
11
|
-
# @option options [required, Hash] :has_many
|
12
|
-
# @option options [required, Hash] :api
|
13
|
-
# @option options [required, Hash] :paginators
|
14
|
-
# @option options [String] :var_name ('')
|
15
|
-
def initialize(options = {})
|
16
|
-
|
17
|
-
name = options.fetch(:name)
|
18
|
-
@has_many = options.fetch(:has_many)
|
19
|
-
@paginators = options.fetch(:paginators)
|
20
|
-
@var_name = options.fetch(:var_name, '')
|
21
|
-
|
22
|
-
super(underscore(name))
|
23
|
-
|
24
|
-
param('options', type:Hash, default:{})
|
25
|
-
|
26
|
-
ClientRequestDocs.new(
|
27
|
-
request: @has_many['request'],
|
28
|
-
api: options.fetch(:api),
|
29
|
-
skip: paging_options,
|
30
|
-
var_name: @var_name,
|
31
|
-
returns: name.downcase,
|
32
|
-
).apply(self)
|
33
|
-
|
34
|
-
paginated? ? paginated_reqeust : non_paginated_request
|
35
|
-
|
36
|
-
returns(collection_class)
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
def paginated_reqeust
|
42
|
-
code do |c1|
|
43
|
-
c1 << 'batches = Enumerator.new do |y|'
|
44
|
-
c1.indent do |c2|
|
45
|
-
c2 << client_request(true)
|
46
|
-
c2 << "resp.each_page do |page|"
|
47
|
-
c2.indent do |c3|
|
48
|
-
c3 << 'batch = []'
|
49
|
-
c3 << BatchBuilder.new(resource: @has_many['resource'], resp_var_name:'page')
|
50
|
-
c3 << 'y.yield(batch)'
|
51
|
-
end
|
52
|
-
c2 << 'end'
|
53
|
-
end
|
54
|
-
c1 << 'end'
|
55
|
-
c1 << "#{collection_class}.new(batches)"
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def non_paginated_request
|
60
|
-
code do |code|
|
61
|
-
code << 'batches = Enumerator.new do |y|'
|
62
|
-
code.indent do |c|
|
63
|
-
c << 'batch = []'
|
64
|
-
c << client_request(true)
|
65
|
-
c << BatchBuilder.new(resource: @has_many['resource'])
|
66
|
-
c << 'y.yield(batch)'
|
67
|
-
end
|
68
|
-
code << 'end'
|
69
|
-
code << "#{collection_class}.new(batches)"
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def client_request(resp)
|
74
|
-
ClientRequest.new(
|
75
|
-
request: @has_many['request'],
|
76
|
-
resp: resp
|
77
|
-
)
|
78
|
-
end
|
79
|
-
|
80
|
-
def collection_class
|
81
|
-
"#{@has_many['resource']['type']}::Collection"
|
82
|
-
end
|
83
|
-
|
84
|
-
def paginated?
|
85
|
-
@paginators &&
|
86
|
-
@paginators['pagination'][operation_name] &&
|
87
|
-
@paginators['pagination'][operation_name]['input_token']
|
88
|
-
end
|
89
|
-
|
90
|
-
def paging_options
|
91
|
-
if paginated?
|
92
|
-
skip = []
|
93
|
-
skip << @paginators['pagination'][operation_name]['input_token']
|
94
|
-
skip << @paginators['pagination'][operation_name]['limit_key']
|
95
|
-
skip.compact
|
96
|
-
else
|
97
|
-
[]
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def operation_name
|
102
|
-
@has_many['request']['operation']
|
103
|
-
end
|
104
|
-
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module AwsSdkCodeGenerator
|
2
|
-
module Generators
|
3
|
-
module Resource
|
4
|
-
class IdentifierGetter < Dsl::Method
|
5
|
-
|
6
|
-
include Helper
|
7
|
-
|
8
|
-
# @option options [required, Hash] :identifier
|
9
|
-
def initialize(options)
|
10
|
-
identifier = options.fetch(:identifier)
|
11
|
-
name = underscore(identifier.fetch('name'))
|
12
|
-
super(name)
|
13
|
-
returns(identifier_type(identifier))
|
14
|
-
code("@#{name}")
|
15
|
-
if
|
16
|
-
identifier['memberName'] &&
|
17
|
-
identifier['memberName'] != identifier['name']
|
18
|
-
then
|
19
|
-
alias_as(underscore(identifier['memberName']))
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
module AwsSdkCodeGenerator
|
2
|
-
module Generators
|
3
|
-
module Resource
|
4
|
-
class IdentifiersMethod < Dsl::Method
|
5
|
-
|
6
|
-
# @option options [required, Array<Hash>] :identifiers
|
7
|
-
def initialize(options = {})
|
8
|
-
identifiers = options.fetch(:identifiers)
|
9
|
-
super('identifiers')
|
10
|
-
docstring('@deprecated')
|
11
|
-
docstring('@api private')
|
12
|
-
identifiers ||= []
|
13
|
-
identifiers = (identifiers || []).inject({}) do |hash, identifier|
|
14
|
-
name = underscore(identifier['name'])
|
15
|
-
hash[name.to_sym] = "@#{name}"
|
16
|
-
hash
|
17
|
-
end
|
18
|
-
code(HashFormatter.new(inline: true).format(identifiers))
|
19
|
-
end
|
20
|
-
|
21
|
-
def lines
|
22
|
-
super + ["deprecated(:#{name})"]
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
module AwsSdkCodeGenerator
|
2
|
-
module Generators
|
3
|
-
module Resource
|
4
|
-
class InitializeMethod < Dsl::Method
|
5
|
-
|
6
|
-
include Helper
|
7
|
-
|
8
|
-
# @option options [required, Hash] :resource]
|
9
|
-
def initialize(options = {})
|
10
|
-
resource = options.fetch(:resource)
|
11
|
-
@identifiers = resource["identifiers"] || []
|
12
|
-
@shape_name = resource["shape"]
|
13
|
-
super('initialize')
|
14
|
-
param('*args')
|
15
|
-
positional_docstring unless @identifiers.empty?
|
16
|
-
options_docstring
|
17
|
-
code('options = Hash === args.last ? args.pop.dup : {}')
|
18
|
-
extract_identifiers
|
19
|
-
if @shape_name
|
20
|
-
code('@data = options.delete(:data)')
|
21
|
-
else
|
22
|
-
code('@data = Aws::EmptyStructure.new')
|
23
|
-
end
|
24
|
-
code('@client = options.delete(:client) || Client.new(options)')
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def positional_docstring
|
30
|
-
names = @identifiers.map { |i| underscore(i['name']) }.join(', ')
|
31
|
-
docstring("@overload def initialize(#{names}, options = {})")
|
32
|
-
identifiers.each do |name, type, n|
|
33
|
-
docstring(" @param [#{type}] #{name}")
|
34
|
-
end
|
35
|
-
apply_client_option
|
36
|
-
end
|
37
|
-
|
38
|
-
def options_docstring
|
39
|
-
docstring("@overload def initialize(options = {})")
|
40
|
-
identifiers.each do |name, type, n|
|
41
|
-
docstring(" @option options [required, #{type}] :#{name}")
|
42
|
-
end
|
43
|
-
apply_client_option
|
44
|
-
end
|
45
|
-
|
46
|
-
def apply_client_option
|
47
|
-
docstring(" @option options [Client] :client")
|
48
|
-
end
|
49
|
-
|
50
|
-
def extract_identifiers
|
51
|
-
identifiers.each do |name, type, n|
|
52
|
-
code("@#{name} = extract_#{name}(args, options)")
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def identifiers
|
57
|
-
Enumerator.new do |y|
|
58
|
-
@identifiers.each.with_index do |i, n|
|
59
|
-
y.yield(underscore(i['name']), identifier_type(i), n)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
module AwsSdkCodeGenerator
|
2
|
-
module Generators
|
3
|
-
module Resource
|
4
|
-
class LoadMethod < Dsl::Method
|
5
|
-
|
6
|
-
LOAD_NOT_IMPLEMENTED =
|
7
|
-
"#load is not implemented, data only available via enumeration"
|
8
|
-
|
9
|
-
# @option options [required, String] :resource_name
|
10
|
-
# @option options [required, Hash] :definition
|
11
|
-
def initialize(options = {})
|
12
|
-
@resource_name = options.fetch(:resource_name)
|
13
|
-
@load = options.fetch(:definition)
|
14
|
-
super('load')
|
15
|
-
alias_as('reload')
|
16
|
-
if @load
|
17
|
-
docstring(load_docstring)
|
18
|
-
code do |c|
|
19
|
-
c << client_request
|
20
|
-
c << "@data = resp.#{load_path}"
|
21
|
-
c << "self"
|
22
|
-
end
|
23
|
-
else
|
24
|
-
docstring('@raise [Errors::ResourceNotLoadable]')
|
25
|
-
docstring('@api private')
|
26
|
-
code do |c|
|
27
|
-
c << "msg = #{LOAD_NOT_IMPLEMENTED.inspect}"
|
28
|
-
c << "raise Errors::ResourceNotLoadable, msg"
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def client_request
|
36
|
-
ClientRequest.new(request: @load['request'], resp: true, merge: false)
|
37
|
-
end
|
38
|
-
|
39
|
-
def load_path
|
40
|
-
if @load['path'] == '@'
|
41
|
-
'data'
|
42
|
-
else
|
43
|
-
@load['path'].downcase
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def operation_name
|
48
|
-
underscore(@load['request']['operation'])
|
49
|
-
end
|
50
|
-
|
51
|
-
def load_docstring
|
52
|
-
<<-MARKDOWN
|
53
|
-
Loads, or reloads {#data} for the current {#{@resource_name}}.
|
54
|
-
Returns `self` making it possible to chain methods.
|
55
|
-
|
56
|
-
#{underscore(@resource_name)}.reload.data
|
57
|
-
|
58
|
-
@return [self]
|
59
|
-
MARKDOWN
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
module AwsSdkCodeGenerator
|
2
|
-
module Generators
|
3
|
-
module Resource
|
4
|
-
class ValueSource < String
|
5
|
-
|
6
|
-
def initialize(value)
|
7
|
-
super(send("param_#{underscore(value['source'])}", value))
|
8
|
-
end
|
9
|
-
|
10
|
-
private
|
11
|
-
|
12
|
-
def param_identifier(param)
|
13
|
-
"@" + underscore(param['name'])
|
14
|
-
end
|
15
|
-
|
16
|
-
def param_data(param)
|
17
|
-
path = param['path']
|
18
|
-
if path == '@'
|
19
|
-
'data'
|
20
|
-
elsif path.match(/^(\w(\[0\])?)+(\.\w+)*$/)
|
21
|
-
'data.' + underscore_path(path)
|
22
|
-
else
|
23
|
-
raise "unsupported path: #{path.inspect}"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def param_response(param)
|
28
|
-
if param['path'] == '@'
|
29
|
-
'resp.data'
|
30
|
-
else
|
31
|
-
'resp.data.' + underscore_path(param['path'])
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def param_request_parameter(param)
|
36
|
-
if param['path'].match(/^\w+(\.\w+)*$/)
|
37
|
-
"options" + path_parts(param['path']).map { |part| "[:#{part}]" }.join
|
38
|
-
else
|
39
|
-
raise "unsupported path expression: #{param['path']}"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def param_string(param)
|
44
|
-
param['value'].inspect
|
45
|
-
end
|
46
|
-
alias param_integer param_string
|
47
|
-
alias param_boolean param_string
|
48
|
-
|
49
|
-
def param_input(param)
|
50
|
-
underscore(param['target'])
|
51
|
-
end
|
52
|
-
|
53
|
-
def underscore(str)
|
54
|
-
Underscore.underscore(str)
|
55
|
-
end
|
56
|
-
|
57
|
-
def underscore_path(path)
|
58
|
-
path.gsub(/\w+/) { |part| underscore(part) }
|
59
|
-
end
|
60
|
-
|
61
|
-
def path_parts(path)
|
62
|
-
path.split('.').map { |part| underscore(part) }
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
module AwsSdkCodeGenerator
|
2
|
-
module Generators
|
3
|
-
module Resource
|
4
|
-
class WaiterMethod < Dsl::Method
|
5
|
-
|
6
|
-
# @option options [required, String] :resource_name
|
7
|
-
# @option options [required, Hash] :resource
|
8
|
-
# @option options [required, String] :resource_waiter_name
|
9
|
-
# @option options [required, Hash] :resource_waiter
|
10
|
-
# @option options [required, Hash] :waiter
|
11
|
-
def initialize(options)
|
12
|
-
resource_name = options.fetch(:resource_name)
|
13
|
-
@resource = options.fetch(:resource)
|
14
|
-
@resource_waiter = options.fetch(:resource_waiter)
|
15
|
-
@waiter_name = @resource_waiter['waiterName']
|
16
|
-
waiter = options.fetch(:waiter)
|
17
|
-
super("wait_until_#{underscore(options.fetch(:resource_waiter_name))}")
|
18
|
-
param('options', type: 'Hash', default:{})
|
19
|
-
option(name: 'max_attempts', type:Integer, default: waiter['maxAttempts'])
|
20
|
-
option(name: 'delay', type:Float, default: waiter['delay'])
|
21
|
-
option(name: 'before_attempt', type:Proc)
|
22
|
-
option(name: 'before_wait', type:Proc)
|
23
|
-
|
24
|
-
returns(resource_name)
|
25
|
-
|
26
|
-
resp = @resource_waiter['path'] ? 'resp = ' : ''
|
27
|
-
code(<<-CODE)
|
28
|
-
options, params = separate_params_and_options(options)
|
29
|
-
waiter = Waiters::#{@waiter_name}.new(options)
|
30
|
-
yield_waiter_and_warn(waiter, &Proc.new) if block_given?
|
31
|
-
#{resp}waiter.wait(params.merge(#{args}))
|
32
|
-
#{resource_name}.new(#{constructor_args})
|
33
|
-
CODE
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
def args
|
39
|
-
ClientRequestParams.new(params: @resource_waiter['params']).to_s.strip
|
40
|
-
end
|
41
|
-
|
42
|
-
def constructor_args
|
43
|
-
args = {}
|
44
|
-
(@resource['identifiers'] || []).each do |i|
|
45
|
-
name = underscore(i['name']).to_sym
|
46
|
-
args[name] = "@#{name}"
|
47
|
-
end
|
48
|
-
if @resource_waiter['path']
|
49
|
-
args[:data] = ValueSource.new(
|
50
|
-
'source' => 'response',
|
51
|
-
'path' => @resource_waiter['path']
|
52
|
-
)
|
53
|
-
end
|
54
|
-
args[:client] = '@client'
|
55
|
-
HashFormatter.new.format(args)
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|