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.
Files changed (131) hide show
  1. checksums.yaml +5 -5
  2. data/lib/aws-sdk-code-generator.rb +68 -75
  3. data/lib/aws-sdk-code-generator/api.rb +130 -0
  4. data/lib/aws-sdk-code-generator/apply_docs.rb +15 -2
  5. data/lib/aws-sdk-code-generator/client_constructor.rb +39 -0
  6. data/lib/aws-sdk-code-generator/client_operation_documentation.rb +268 -0
  7. data/lib/aws-sdk-code-generator/client_operation_list.rb +148 -0
  8. data/lib/aws-sdk-code-generator/client_response_structure_example.rb +108 -0
  9. data/lib/aws-sdk-code-generator/code_builder.rb +146 -133
  10. data/lib/aws-sdk-code-generator/crosslink.rb +42 -0
  11. data/lib/aws-sdk-code-generator/docstring.rb +199 -0
  12. data/lib/aws-sdk-code-generator/error_list.rb +77 -0
  13. data/lib/aws-sdk-code-generator/errors.rb +2 -0
  14. data/lib/aws-sdk-code-generator/eventstream_example.rb +220 -0
  15. data/lib/aws-sdk-code-generator/gem_builder.rb +19 -25
  16. data/lib/aws-sdk-code-generator/hash_formatter.rb +5 -2
  17. data/lib/aws-sdk-code-generator/helper.rb +77 -61
  18. data/lib/aws-sdk-code-generator/plugin_list.rb +146 -0
  19. data/lib/aws-sdk-code-generator/resource_action.rb +69 -0
  20. data/lib/aws-sdk-code-generator/resource_action_code.rb +57 -0
  21. data/lib/aws-sdk-code-generator/resource_association.rb +37 -0
  22. data/lib/aws-sdk-code-generator/resource_attribute.rb +76 -0
  23. data/lib/aws-sdk-code-generator/resource_batch_action.rb +56 -0
  24. data/lib/aws-sdk-code-generator/resource_batch_action_code.rb +136 -0
  25. data/lib/aws-sdk-code-generator/resource_batch_action_documentation.rb +108 -0
  26. data/lib/aws-sdk-code-generator/resource_batch_builder.rb +212 -0
  27. data/lib/aws-sdk-code-generator/resource_builder.rb +48 -0
  28. data/lib/aws-sdk-code-generator/resource_client_request.rb +62 -0
  29. data/lib/aws-sdk-code-generator/resource_client_request_documentation.rb +81 -0
  30. data/lib/aws-sdk-code-generator/resource_client_request_params.rb +86 -0
  31. data/lib/aws-sdk-code-generator/resource_data_method.rb +60 -0
  32. data/lib/aws-sdk-code-generator/resource_has_association.rb +117 -0
  33. data/lib/aws-sdk-code-generator/resource_has_many_association.rb +52 -0
  34. data/lib/aws-sdk-code-generator/resource_has_many_association_code.rb +76 -0
  35. data/lib/aws-sdk-code-generator/resource_identifier.rb +44 -0
  36. data/lib/aws-sdk-code-generator/resource_identifiers_method.rb +29 -0
  37. data/lib/aws-sdk-code-generator/resource_load_method.rb +68 -0
  38. data/lib/aws-sdk-code-generator/resource_method.rb +22 -0
  39. data/lib/aws-sdk-code-generator/resource_skip_params.rb +36 -0
  40. data/lib/aws-sdk-code-generator/resource_value_source.rb +68 -0
  41. data/lib/aws-sdk-code-generator/resource_waiter.rb +80 -0
  42. data/lib/aws-sdk-code-generator/service.rb +30 -7
  43. data/lib/aws-sdk-code-generator/shared_example.rb +131 -0
  44. data/lib/aws-sdk-code-generator/syntax_example.rb +60 -0
  45. data/lib/aws-sdk-code-generator/syntax_example_hash.rb +174 -0
  46. data/lib/aws-sdk-code-generator/underscore.rb +10 -5
  47. data/lib/aws-sdk-code-generator/view.rb +33 -0
  48. data/lib/aws-sdk-code-generator/views.rb +2 -0
  49. data/lib/aws-sdk-code-generator/views/apig_endpoint_class.rb +25 -0
  50. data/lib/aws-sdk-code-generator/views/apig_readme.rb +32 -0
  51. data/lib/aws-sdk-code-generator/views/async_client_class.rb +68 -0
  52. data/lib/aws-sdk-code-generator/views/authorizer_class.rb +17 -0
  53. data/lib/aws-sdk-code-generator/views/client_api_module.rb +583 -0
  54. data/lib/aws-sdk-code-generator/views/client_class.rb +93 -0
  55. data/lib/aws-sdk-code-generator/views/docstring.rb +27 -0
  56. data/lib/aws-sdk-code-generator/views/errors_module.rb +32 -0
  57. data/lib/aws-sdk-code-generator/views/event_streams_module.rb +149 -0
  58. data/lib/aws-sdk-code-generator/views/features/env.rb +9 -0
  59. data/lib/aws-sdk-code-generator/views/features/smoke.rb +51 -0
  60. data/lib/aws-sdk-code-generator/views/features/smoke_step_definitions.rb +26 -0
  61. data/lib/aws-sdk-code-generator/views/features/step_definitions.rb +2 -0
  62. data/lib/aws-sdk-code-generator/views/gemspec.rb +39 -5
  63. data/lib/aws-sdk-code-generator/views/resource_class.rb +122 -0
  64. data/lib/aws-sdk-code-generator/views/root_resource_class.rb +58 -0
  65. data/lib/aws-sdk-code-generator/views/service_module.rb +30 -14
  66. data/lib/aws-sdk-code-generator/views/spec/spec_helper.rb +9 -0
  67. data/lib/aws-sdk-code-generator/views/types_module.rb +294 -0
  68. data/lib/aws-sdk-code-generator/views/version.rb +2 -0
  69. data/lib/aws-sdk-code-generator/views/waiters_module.rb +37 -0
  70. data/lib/aws-sdk-code-generator/waiter.rb +95 -0
  71. data/lib/aws-sdk-code-generator/yard_option_tag.rb +43 -0
  72. metadata +61 -68
  73. data/lib/aws-sdk-code-generator/dsl/access_control_statement.rb +0 -23
  74. data/lib/aws-sdk-code-generator/dsl/attribute_accessor.rb +0 -43
  75. data/lib/aws-sdk-code-generator/dsl/attribute_reader.rb +0 -11
  76. data/lib/aws-sdk-code-generator/dsl/attribute_writer.rb +0 -11
  77. data/lib/aws-sdk-code-generator/dsl/autoload_statement.rb +0 -15
  78. data/lib/aws-sdk-code-generator/dsl/block_param.rb +0 -11
  79. data/lib/aws-sdk-code-generator/dsl/class.rb +0 -27
  80. data/lib/aws-sdk-code-generator/dsl/code_literal.rb +0 -66
  81. data/lib/aws-sdk-code-generator/dsl/code_object.rb +0 -33
  82. data/lib/aws-sdk-code-generator/dsl/docstring.rb +0 -36
  83. data/lib/aws-sdk-code-generator/dsl/eigenclass.rb +0 -15
  84. data/lib/aws-sdk-code-generator/dsl/extend_statement.rb +0 -12
  85. data/lib/aws-sdk-code-generator/dsl/formatter.rb +0 -25
  86. data/lib/aws-sdk-code-generator/dsl/include_statement.rb +0 -17
  87. data/lib/aws-sdk-code-generator/dsl/main.rb +0 -105
  88. data/lib/aws-sdk-code-generator/dsl/method.rb +0 -108
  89. data/lib/aws-sdk-code-generator/dsl/module.rb +0 -167
  90. data/lib/aws-sdk-code-generator/dsl/option_tag.rb +0 -36
  91. data/lib/aws-sdk-code-generator/dsl/param.rb +0 -43
  92. data/lib/aws-sdk-code-generator/dsl/param_list.rb +0 -38
  93. data/lib/aws-sdk-code-generator/dsl/return_tag.rb +0 -19
  94. data/lib/aws-sdk-code-generator/dsl/tag_default.rb +0 -20
  95. data/lib/aws-sdk-code-generator/dsl/tag_docstring.rb +0 -27
  96. data/lib/aws-sdk-code-generator/dsl/tag_type.rb +0 -18
  97. data/lib/aws-sdk-code-generator/generators/client_api_module.rb +0 -334
  98. data/lib/aws-sdk-code-generator/generators/client_class.rb +0 -389
  99. data/lib/aws-sdk-code-generator/generators/client_operation_documentation.rb +0 -166
  100. data/lib/aws-sdk-code-generator/generators/errors_module.rb +0 -25
  101. data/lib/aws-sdk-code-generator/generators/resource/action.rb +0 -88
  102. data/lib/aws-sdk-code-generator/generators/resource/batch_builder.rb +0 -211
  103. data/lib/aws-sdk-code-generator/generators/resource/builder.rb +0 -50
  104. data/lib/aws-sdk-code-generator/generators/resource/client_getter.rb +0 -15
  105. data/lib/aws-sdk-code-generator/generators/resource/client_request.rb +0 -49
  106. data/lib/aws-sdk-code-generator/generators/resource/client_request_docs.rb +0 -97
  107. data/lib/aws-sdk-code-generator/generators/resource/client_request_params.rb +0 -88
  108. data/lib/aws-sdk-code-generator/generators/resource/collection_class.rb +0 -180
  109. data/lib/aws-sdk-code-generator/generators/resource/data_attribute_getter.rb +0 -24
  110. data/lib/aws-sdk-code-generator/generators/resource/data_loaded_method.rb +0 -18
  111. data/lib/aws-sdk-code-generator/generators/resource/data_method.rb +0 -49
  112. data/lib/aws-sdk-code-generator/generators/resource/exists_method.rb +0 -29
  113. data/lib/aws-sdk-code-generator/generators/resource/extract_identifier_method.rb +0 -32
  114. data/lib/aws-sdk-code-generator/generators/resource/has_association.rb +0 -101
  115. data/lib/aws-sdk-code-generator/generators/resource/has_many_association.rb +0 -108
  116. data/lib/aws-sdk-code-generator/generators/resource/identifier_getter.rb +0 -26
  117. data/lib/aws-sdk-code-generator/generators/resource/identifiers_method.rb +0 -28
  118. data/lib/aws-sdk-code-generator/generators/resource/initialize_method.rb +0 -67
  119. data/lib/aws-sdk-code-generator/generators/resource/load_method.rb +0 -65
  120. data/lib/aws-sdk-code-generator/generators/resource/value_source.rb +0 -68
  121. data/lib/aws-sdk-code-generator/generators/resource/waiter_method.rb +0 -61
  122. data/lib/aws-sdk-code-generator/generators/resource_class.rb +0 -325
  123. data/lib/aws-sdk-code-generator/generators/response_structure_example.rb +0 -83
  124. data/lib/aws-sdk-code-generator/generators/root_resource_class.rb +0 -42
  125. data/lib/aws-sdk-code-generator/generators/service_documentation.rb +0 -64
  126. data/lib/aws-sdk-code-generator/generators/shared_example.rb +0 -132
  127. data/lib/aws-sdk-code-generator/generators/structure_type_class.rb +0 -95
  128. data/lib/aws-sdk-code-generator/generators/syntax_example.rb +0 -169
  129. data/lib/aws-sdk-code-generator/generators/types_module.rb +0 -52
  130. data/lib/aws-sdk-code-generator/generators/waiter_class.rb +0 -62
  131. data/lib/aws-sdk-code-generator/generators/waiters_module.rb +0 -20
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AwsSdkCodeGenerator
4
+ class ResourceDataMethod
5
+ class << self
6
+
7
+ # @param [String] class_name
8
+ # @param [Hash] resource
9
+ # @return [ResourceMethod]
10
+ def build(class_name, resource)
11
+ if resource['load']
12
+ data_method(class_name, resource)
13
+ elsif resource['shape']
14
+ data_without_load(class_name, resource)
15
+ else
16
+ empty_data_method
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def empty_data_method
23
+ ResourceMethod.new.tap do |m|
24
+ m.method_name = 'data'
25
+ m.arguments = nil
26
+ m.documentation = "# @api private\n# @return [EmptyStructure]"
27
+ m.code = '@data'
28
+ end
29
+ end
30
+
31
+ def data_without_load(class_name, resource)
32
+ ResourceMethod.new.tap do |m|
33
+ m.method_name = 'data'
34
+ m.arguments = nil
35
+ m.documentation = "# @raise [NotImplementedError] Raises when {#data_loaded?} is `false`.\n# @return [Types::#{resource['shape']}]\n# Returns the data for this {#{class_name}}."
36
+ m.code = "load unless @data\n@data"
37
+ end
38
+ end
39
+
40
+ def data_method(class_name, resource)
41
+ ResourceMethod.new.tap do |m|
42
+ m.method_name = 'data'
43
+ m.arguments = nil
44
+ m.documentation = "# @return [Types::#{resource['shape']}]\n# Returns the data for this {#{class_name}}. Calls\n# {Client##{Underscore.underscore(resource['load']['request']['operation'])}} if {#data_loaded?} is `false`."
45
+ m.code = "load unless @data\n@data"
46
+ end
47
+ end
48
+
49
+ def data_path(resource)
50
+ path = resource['load']['path']
51
+ if path == '@'
52
+ 'data'
53
+ else
54
+ Underscore.underscore_jmespath(path)
55
+ end
56
+ end
57
+
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,117 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AwsSdkCodeGenerator
4
+ class ResourceHasAssociation
5
+ class << self
6
+
7
+ # @return [ResourceMethod]
8
+ def build(options)
9
+ assoc = options.fetch(:assoc)
10
+ params = compute_params(assoc)
11
+ ResourceMethod.new.tap do |m|
12
+ m.method_name = Underscore.underscore(options.fetch(:name))
13
+ m.arguments = arguments(params)
14
+ m.documentation = documentation(assoc, params)
15
+ m.code = code(assoc)
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def code(assoc)
22
+ parts = []
23
+ if plural?(assoc)
24
+ parts << 'batch = []'
25
+ parts << ResourceBatchBuilder.new(resource: assoc['resource']).build
26
+ parts << "#{assoc['resource']['type']}::Collection.new([batch], size: batch.size)"
27
+ elsif nullable?(assoc) # singular association
28
+ parts << "if #{null_checks(assoc)}"
29
+ parts << " #{Docstring.indent(builder(assoc))}"
30
+ parts << 'else'
31
+ parts << ' nil'
32
+ parts << 'end'
33
+ else
34
+ parts << builder(assoc)
35
+ end
36
+ parts.join("\n").rstrip
37
+ end
38
+
39
+ def builder(assoc)
40
+ ResourceBuilder.new(resource: assoc['resource'], request_made: false).build
41
+ end
42
+
43
+ def documentation(assoc, params)
44
+ parts = []
45
+ params.each do |param|
46
+ parts << "# @param [#{param[:type]}] #{param[:name]}"
47
+ end
48
+ parts << "# @return [#{return_type(assoc)}]"
49
+ parts.join("\n").rstrip
50
+ end
51
+
52
+ def return_type(assoc)
53
+ type = assoc['resource']['type']
54
+ if plural?(assoc)
55
+ "#{type}::Collection"
56
+ elsif nullable?(assoc)
57
+ "#{type}, nil"
58
+ else
59
+ type
60
+ end
61
+ end
62
+
63
+ def compute_params(assoc)
64
+ params = []
65
+ (assoc['resource']['identifiers'] || []).each do |identifier|
66
+ if identifier['source'] == 'input'
67
+ params << {
68
+ name: Underscore.underscore(identifier['target']),
69
+ type: 'String',
70
+ }
71
+ end
72
+ end
73
+ params
74
+ end
75
+
76
+ def arguments(params)
77
+ if params.empty?
78
+ nil
79
+ else
80
+ params.map { |p| p[:name] }.join(', ')
81
+ end
82
+ end
83
+
84
+ def plural?(assoc)
85
+ plural = false
86
+ r = assoc['resource']
87
+ (r['identifiers'] || []).each do |i|
88
+ if i['path'] && i['path'].include?('[]')
89
+ plural = true
90
+ break
91
+ end
92
+ end
93
+ plural = true if r['data'] && r['data'].include?('[]')
94
+ plural
95
+ end
96
+
97
+ def nullable?(assoc)
98
+ !data_identifiers(assoc).empty?
99
+ end
100
+
101
+ def data_identifiers(assoc)
102
+ identifiers = []
103
+ (assoc['resource']['identifiers'] || []).each do |i|
104
+ identifiers << i if i['source'] == 'data'
105
+ end
106
+ identifiers
107
+ end
108
+
109
+ def null_checks(assoc)
110
+ data_identifiers(assoc).map do |i|
111
+ ResourceValueSource.new(i)
112
+ end.join(' && ')
113
+ end
114
+
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AwsSdkCodeGenerator
4
+ class ResourceHasManyAssociation
5
+ class << self
6
+
7
+ # @return [ResourceMethod]
8
+ def build(options)
9
+ ResourceMethod.new.tap do |m|
10
+ m.method_name = Underscore.underscore(options.fetch(:name))
11
+ m.arguments = 'options = {}'
12
+ m.code = ResourceHasManyAssociationCode.new(options).build
13
+ m.documentation = documentation(options)
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def documentation(options)
20
+ ResourceClientReqeustDocumentation.new(
21
+ method_name: Underscore.underscore(options.fetch(:name)),
22
+ receiver: Underscore.underscore(options.fetch(:class_name)),
23
+ resp_var: Underscore.underscore(options.fetch(:name)),
24
+ returns: "#{options.fetch(:assoc)['resource']['type']}::Collection",
25
+ request: options.fetch(:assoc)['request'],
26
+ api: options.fetch(:api),
27
+ skip: paging_options(options),
28
+ ).build
29
+ end
30
+
31
+ def paging_options(options)
32
+ paginators = options.fetch(:paginators, nil)
33
+ operation_name = options.fetch(:assoc).fetch('request').fetch('operation')
34
+ if paginated?(operation_name, paginators)
35
+ skip = []
36
+ skip << paginators['pagination'][operation_name]['input_token']
37
+ skip << paginators['pagination'][operation_name]['limit_key']
38
+ skip.compact
39
+ else
40
+ []
41
+ end
42
+ end
43
+
44
+ def paginated?(operation_name, paginators)
45
+ paginators &&
46
+ paginators['pagination'][operation_name] &&
47
+ paginators['pagination'][operation_name]['input_token']
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AwsSdkCodeGenerator
4
+ class ResourceHasManyAssociationCode
5
+
6
+ def initialize(options)
7
+ @assoc = options.fetch(:assoc)
8
+ @paginators = options.fetch(:paginators, nil)
9
+ @collection_class = "#{options.fetch(:assoc)['resource']['type']}::Collection"
10
+ end
11
+
12
+ def build
13
+ if paginated?
14
+ paginated_request
15
+ else
16
+ non_paginated_request
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def paginated_request
23
+ <<-CODE.rstrip
24
+ batches = Enumerator.new do |y|
25
+ #{client_request}
26
+ resp.each_page do |page|
27
+ batch = []
28
+ #{batch_builder(resp_var_name: 'page', indent: ' ')}
29
+ y.yield(batch)
30
+ end
31
+ end
32
+ #{@collection_class}.new(batches)
33
+ CODE
34
+ end
35
+
36
+ def non_paginated_request
37
+ <<-CODE.rstrip
38
+ batches = Enumerator.new do |y|
39
+ batch = []
40
+ #{client_request}
41
+ #{batch_builder(indent: ' ')}
42
+ y.yield(batch)
43
+ end
44
+ #{@collection_class}.new(batches)
45
+ CODE
46
+ end
47
+
48
+ def client_request
49
+ Docstring.indent(ResourceClientRequest.build(
50
+ request: @assoc['request'],
51
+ merge: true,
52
+ resp: true,
53
+ ), ' ')
54
+ end
55
+
56
+ def batch_builder(options)
57
+ Docstring.indent(
58
+ ResourceBatchBuilder.new(
59
+ resource: @assoc['resource'],
60
+ resp_var_name: options.fetch(:resp_var_name, 'resp'),
61
+ ).build,
62
+ options[:indent])
63
+ end
64
+
65
+ def paginated?
66
+ @paginators &&
67
+ @paginators['pagination'][operation_name] &&
68
+ @paginators['pagination'][operation_name]['input_token']
69
+ end
70
+
71
+ def operation_name
72
+ @assoc['request']['operation']
73
+ end
74
+
75
+ end
76
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AwsSdkCodeGenerator
4
+ class ResourceIdentifier
5
+
6
+ # @return [String]
7
+ attr_accessor :name
8
+
9
+ # @return [String]
10
+ attr_accessor :type
11
+
12
+ # @return [String, nil]
13
+ attr_accessor :offset
14
+
15
+ # @return [String, nil]
16
+ attr_accessor :alias
17
+
18
+ class << self
19
+
20
+ # @return [Array<ResourceIdentifier>)
21
+ def build_list(resource)
22
+ resource.fetch('identifiers', []).each.with_index.map do |i, n|
23
+ ResourceIdentifier.new.tap do |identifier|
24
+ identifier.name = Underscore.underscore(i['name'])
25
+ identifier.type = Docstring.ucfirst(i['type'] || 'String')
26
+ identifier.offset = n
27
+ identifier.alias = identifier_alias(i)
28
+ end
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def identifier_alias(identifier)
35
+ if identifier['memberName'] && identifier['memberName'] != identifier['name']
36
+ Underscore.underscore(identifier['memberName'])
37
+ else
38
+ nil
39
+ end
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AwsSdkCodeGenerator
4
+ class ResourceIdentifiersMethod
5
+ class << self
6
+
7
+ # @param [ResourceIdentifier] identifiers
8
+ # @return [ResourceMethod
9
+ def build(identifiers)
10
+ ResourceMethod.new.tap do |m|
11
+ m.method_name = 'identifiers'
12
+ m.arguments = nil
13
+ m.documentation = "# @deprecated\n# @api private"
14
+ m.code = code(identifiers)
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def code(identifiers)
21
+ hash = identifiers.inject({}) do |hash, identifier|
22
+ hash[identifier.name.to_sym] = "@#{identifier.name}"
23
+ hash
24
+ end
25
+ HashFormatter.new(inline: true).format(hash)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AwsSdkCodeGenerator
4
+ class ResourceLoadMethod
5
+ class << self
6
+
7
+ # @param [String] class_name
8
+ # @param [Hash] resource
9
+ # @return [ResourceMethod]
10
+ def build(class_name, resource)
11
+ if resource['load']
12
+ load_method(class_name, resource)
13
+ else
14
+ empty_load_method
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def empty_load_method
21
+ ResourceMethod.new.tap do |m|
22
+ m.method_name = 'load'
23
+ m.arguments = nil
24
+ m.documentation = "# @raise [NotImplementedError]\n# @api private"
25
+ m.code = "msg = \"#load is not implemented, data only available via enumeration\"\nraise NotImplementedError, msg"
26
+ end
27
+ end
28
+
29
+ def load_method(class_name, resource)
30
+ ResourceMethod.new.tap do |m|
31
+ m.method_name = 'load'
32
+ m.arguments = nil
33
+ m.documentation = <<-DOCS.rstrip
34
+ # Loads, or reloads {#data} for the current {#{class_name}}.
35
+ # Returns `self` making it possible to chain methods.
36
+ #
37
+ # #{Underscore.underscore(class_name)}.reload.data
38
+ #
39
+ # @return [self]
40
+ DOCS
41
+ m.code = <<-CODE.rstrip
42
+ #{request(resource)}
43
+ @data = resp.#{data_path(resource)}
44
+ self
45
+ CODE
46
+ end
47
+ end
48
+
49
+ def request(resource)
50
+ ResourceClientRequest.build(
51
+ request: resource['load']['request'],
52
+ merge: false,
53
+ resp: true
54
+ )
55
+ end
56
+
57
+ def data_path(resource)
58
+ path = resource['load']['path']
59
+ if path == '@'
60
+ 'data'
61
+ else
62
+ Underscore.underscore_jmespath(path)
63
+ end
64
+ end
65
+
66
+ end
67
+ end
68
+ end