aws-sdk-resources 2.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +7 -0
  2. data/lib/aws-sdk-resources.rb +36 -0
  3. data/lib/aws-sdk-resources/batch.rb +100 -0
  4. data/lib/aws-sdk-resources/builder.rb +86 -0
  5. data/lib/aws-sdk-resources/builder_sources.rb +136 -0
  6. data/lib/aws-sdk-resources/collection.rb +137 -0
  7. data/lib/aws-sdk-resources/definition.rb +363 -0
  8. data/lib/aws-sdk-resources/documenter.rb +18 -0
  9. data/lib/aws-sdk-resources/documenter/base_operation_documenter.rb +269 -0
  10. data/lib/aws-sdk-resources/documenter/data_operation_documenter.rb +47 -0
  11. data/lib/aws-sdk-resources/documenter/enumerate_data_operation_documenter.rb +50 -0
  12. data/lib/aws-sdk-resources/documenter/enumerate_resource_operation_documenter.rb +69 -0
  13. data/lib/aws-sdk-resources/documenter/operation_documenter.rb +43 -0
  14. data/lib/aws-sdk-resources/documenter/reference_operation_documenter.rb +102 -0
  15. data/lib/aws-sdk-resources/documenter/resource_operation_documenter.rb +65 -0
  16. data/lib/aws-sdk-resources/documenter/waiter_operation_documenter.rb +81 -0
  17. data/lib/aws-sdk-resources/errors.rb +15 -0
  18. data/lib/aws-sdk-resources/operation_methods.rb +53 -0
  19. data/lib/aws-sdk-resources/operations.rb +294 -0
  20. data/lib/aws-sdk-resources/options.rb +23 -0
  21. data/lib/aws-sdk-resources/request.rb +39 -0
  22. data/lib/aws-sdk-resources/request_params.rb +225 -0
  23. data/lib/aws-sdk-resources/resource.rb +137 -0
  24. data/lib/aws-sdk-resources/source.rb +39 -0
  25. data/lib/aws-sdk-resources/validator.rb +152 -0
  26. data/lib/aws-sdk-resources/validator/context.rb +60 -0
  27. data/lib/aws-sdk-resources/validator/identifier_validator.rb +107 -0
  28. data/lib/aws-sdk-resources/validator/operation_validator.rb +352 -0
  29. data/lib/aws-sdk-resources/validator/rule.rb +45 -0
  30. data/lib/aws-sdk-resources/validator/shape_validator.rb +47 -0
  31. metadata +87 -0
@@ -0,0 +1,47 @@
1
+ module Aws
2
+ module Resources
3
+ class Documenter
4
+ class DataOperationDocumenter < BaseOperationDocumenter
5
+
6
+ def docstring
7
+ if plural?
8
+ super + " Calls {#{called_operation}}, returning an array of {#{path_type}} objects."
9
+ else
10
+ super + " Calls {#{called_operation}}, returning a #{return_type.first}."
11
+ end
12
+ end
13
+
14
+ def return_message
15
+ if plural? && structure?
16
+ "an array of {Structure structures} with the following memers:\n" + data_members
17
+ elsif structure?
18
+ "a {Structure} with the following members:\n" + data_members
19
+ else
20
+ ''
21
+ end
22
+ end
23
+
24
+ def data_members
25
+ "\n" + path_shape.member_names.map{ |n| "\n* `#{n}`" }.join("\n")
26
+ end
27
+
28
+ def return_type
29
+ if plural?
30
+ ["Array<#{path_type}>"]
31
+ else
32
+ [path_type]
33
+ end
34
+ end
35
+
36
+ def plural?
37
+ !!@operation.path.match(/\[/)
38
+ end
39
+
40
+ def structure?
41
+ Seahorse::Model::Shapes::Structure === path_shape
42
+ end
43
+
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,50 @@
1
+ module Aws
2
+ module Resources
3
+ class Documenter
4
+ class EnumerateDataOperationDocumenter < BaseOperationDocumenter
5
+
6
+ def docstring
7
+ super + ' ' + <<-DOCSTRING.lstrip
8
+ Returns an enumerator that yields #{operation_name.gsub('_', ' ')}.
9
+ No API requests are made until you call an enumerable method.
10
+ {#{called_operation}} will be called multiple times until all results
11
+ have been yielded.
12
+ DOCSTRING
13
+ end
14
+
15
+ def return_type
16
+ ["Enumerator<#{path_type}>"]
17
+ end
18
+
19
+ def return_message
20
+ msg = "Returns an enumerator that yields #{operation_name.gsub('_', ' ')}."
21
+ msg << data_members
22
+ msg
23
+ end
24
+
25
+ def data_members
26
+ if path_shape.type == 'structure'
27
+ msg = "\nEnumerated values have the following properties:\n"
28
+ path_shape.member_names.each do |name|
29
+ msg << "\n* `#{name}`"
30
+ end
31
+ msg
32
+ else
33
+ ''
34
+ end
35
+ end
36
+
37
+ def example_tags
38
+ tag = <<-EXAMPLE.strip
39
+ @example Enumerate all #{operation_name}
40
+ #{variable_name}.#{operation_name}.each do |data|
41
+ # ...
42
+ end
43
+ EXAMPLE
44
+ YARD::DocstringParser.new.parse(tag).to_docstring.tags
45
+ end
46
+
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,69 @@
1
+ module Aws
2
+ module Resources
3
+ class Documenter
4
+ class EnumerateResourceOperationDocumenter < BaseOperationDocumenter
5
+
6
+ def docstring
7
+ super + ' ' +<<-DOCSTRING.lstrip
8
+ Returns a {Resources::Collection Collection} of {#{target_resource_class_name}}
9
+ resources. No API requests are made until you call an enumerable method on the
10
+ collection. {#{called_operation}} will be called multiple times until every
11
+ {#{target_resource_class_name}} has been yielded.
12
+ DOCSTRING
13
+ end
14
+
15
+ def return_type
16
+ ["Collection<#{target_resource_class_name}>"]
17
+ end
18
+
19
+ def return_message
20
+ "a {Aws::Resources::Collection Collection} of {#{target_resource_class_name}} resource objects."
21
+ end
22
+
23
+ def example_tags
24
+ tags = []
25
+ tags << enumerate_example
26
+ tags << enumerate_with_limit_example
27
+ tags << batch_examples if target_resource_batches?
28
+ YARD::DocstringParser.new.parse(tags.join("\n")).to_docstring.tags
29
+ end
30
+
31
+ def enumerate_example
32
+ return <<EXAMPLE
33
+ @example Enumerating {#{target_resource_class_name}} resources.
34
+ #{variable_name}.#{@operation_name}.each do |#{target_resource_class_name.downcase}|
35
+ # yields each #{target_resource_class_name.downcase}
36
+ end
37
+ EXAMPLE
38
+ end
39
+
40
+ def enumerate_with_limit_example
41
+ return <<EXAMPLE
42
+ @example Enumerating {#{target_resource_class_name}} resources with a limit.
43
+ #{variable_name}.#{@operation_name}.limit(10).each do |#{target_resource_class_name.downcase}|
44
+ # yields at most 10 #{@operation_name}
45
+ end
46
+ EXAMPLE
47
+ end
48
+
49
+ def batch_examples
50
+ example = "@example Batch operations callable on the returned collection"
51
+ target_resource_batch_operations.each do |name|
52
+ example << "\n #{variable_name}.#{@operation_name}.#{name}"
53
+ end
54
+ example
55
+ end
56
+
57
+ def target_resource_batches?
58
+ target_resource_class.const_defined?(:Batch) &&
59
+ target_resource_batch_operations.count > 0
60
+ end
61
+
62
+ def target_resource_batch_operations
63
+ target_resource_class::Batch.operation_names
64
+ end
65
+
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,43 @@
1
+ module Aws
2
+ module Resources
3
+ class Documenter
4
+ class OperationDocumenter < BaseOperationDocumenter
5
+
6
+ def docstring
7
+ super + " #{return_base_message}"
8
+ end
9
+
10
+ def return_type
11
+ if returns_data_members
12
+ ['Structure']
13
+ else
14
+ ['void']
15
+ end
16
+ end
17
+
18
+ def return_message
19
+ "#{return_base_message} #{returns_data_members}"
20
+ end
21
+
22
+ def return_base_message
23
+ if returns_data_members
24
+ "Calls {#{called_operation}}, returning its reponse."
25
+ end
26
+ end
27
+
28
+ def returns_data_members
29
+ if response_shape && response_shape.member_names.count > 0
30
+ msg = "The response data has following properties:\n"
31
+ response_shape.member_names.each do |name|
32
+ msg << "\n* `#{name}`"
33
+ end
34
+ msg
35
+ else
36
+ nil
37
+ end
38
+ end
39
+
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,102 @@
1
+ module Aws
2
+ module Resources
3
+ class Documenter
4
+ class ReferenceOperationDocumenter < BaseOperationDocumenter
5
+
6
+ def docstring
7
+ docs = []
8
+ docs << super
9
+
10
+ if can_return_nil?
11
+ docs << return_message
12
+ elsif argument?
13
+ msg = "Returns a {#{target_resource_class}} resource with "
14
+ msg << "the given `#{argument_name}`."
15
+ docs << msg
16
+ else
17
+ docs << "Returns a {#{target_resource_class}} resource."
18
+ end
19
+
20
+ if data_member && resource_class.load_operation
21
+ load_method = resource_class.load_operation.request.method_name
22
+ msg = "Calling this method will call {Client##{load_method}} "
23
+ msg << "unless the resource is already {#data_loaded? loaded}. "
24
+ msg << "No additional API requests are made."
25
+ docs << msg
26
+ else
27
+ msg = "Calling this method will **not** make an API request."
28
+ docs << msg
29
+ end
30
+
31
+ docs.join(' ')
32
+ end
33
+
34
+ def return_type
35
+ if plural?
36
+ type = ["Array<#{target_resource_class_name}>"]
37
+ else
38
+ type = [target_resource_class_name]
39
+ end
40
+ type << 'nil' if can_return_nil?
41
+ type
42
+ end
43
+
44
+ def return_message
45
+ if can_return_nil?
46
+ "Returns a {#{target_resource_class_name}} resource, or `nil` " +
47
+ "if `#data.#{data_member_source}` is `nil`."
48
+ else
49
+ "Returns a {#{target_resource_class_name}} resource."
50
+ end
51
+ end
52
+
53
+ def parameters
54
+ if argument?
55
+ [[argument_name, nil]]
56
+ else
57
+ []
58
+ end
59
+ end
60
+
61
+ def tags
62
+ tags = super
63
+ if argument?
64
+ tag = "@param [String] #{argument_name} "
65
+ tag << "The {#{target_resource_class_name}##{argument_name}} "
66
+ tag << "identifier."
67
+ tags += YARD::DocstringParser.new.parse(tag).to_docstring.tags
68
+ end
69
+ tags
70
+ end
71
+
72
+ def plural?
73
+ @operation.builder.plural?
74
+ end
75
+
76
+ def argument?
77
+ @operation.arity > 0
78
+ end
79
+
80
+ def can_return_nil?
81
+ data_member
82
+ end
83
+
84
+ def data_member
85
+ builder.sources.find { |s| BuilderSources::DataMember === s }
86
+ end
87
+
88
+ def data_member_source
89
+ data_member.source
90
+ end
91
+
92
+ def argument_name
93
+ argument = builder.sources.find do |source|
94
+ BuilderSources::Argument === source
95
+ end
96
+ argument.target.to_s
97
+ end
98
+
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,65 @@
1
+ module Aws
2
+ module Resources
3
+ class Documenter
4
+ class ResourceOperationDocumenter < BaseOperationDocumenter
5
+
6
+ def initialize(*args)
7
+ super
8
+ @plural = @operation.builder.plural?
9
+ end
10
+
11
+ # @return [Boolean] Returns `true` if this operation returns an
12
+ # array of resource objects. Returns `false` if this method returns
13
+ # a single resource object.
14
+ attr_reader :plural
15
+
16
+ alias plural? plural
17
+
18
+ def docstring
19
+ super + ' ' "#{return_message} Calls {#{called_operation}}."
20
+ end
21
+
22
+ def return_type
23
+ if plural?
24
+ ["Array<#{target_resource_class_name}>"]
25
+ else
26
+ [target_resource_class_name]
27
+ end
28
+ end
29
+
30
+ def return_message
31
+ if plural?
32
+ "Returns an array of {#{target_resource_class_name}} resources."
33
+ else
34
+ "Returns a {#{target_resource_class_name}} resource."
35
+ end
36
+ end
37
+
38
+ def example_tags
39
+ id = target_resource_class.identifiers.last.to_s
40
+ idv = target_resource_class_name.downcase + '-' + id.gsub('_', '-')
41
+ tag = []
42
+ tag << "@example Basic usage"
43
+ tag << " #{resp_variable} = #{variable_name}.#{operation_name}(params)"
44
+ if plural?
45
+ tag << " #{resp_variable}.map(&:#{id})"
46
+ tag << " #=> [#{idv.inspect}, ...]"
47
+ else
48
+ tag << " #{resp_variable}.#{id}"
49
+ tag << " #=> #{idv.inspect}"
50
+ end
51
+ YARD::DocstringParser.new.parse(tag).to_docstring.tags
52
+ end
53
+
54
+ def resp_variable
55
+ if plural?
56
+ target_resource_class_name.downcase + 's'
57
+ else
58
+ target_resource_class_name.downcase
59
+ end
60
+ end
61
+
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,81 @@
1
+ module Aws
2
+ module Resources
3
+ class Documenter
4
+ class WaiterOperationDocumenter < BaseOperationDocumenter
5
+
6
+ def docstring
7
+ super + ' ' + <<-DOCSTRING.lstrip
8
+ Waits until this #{resource_class_name} is #{state}. This method
9
+ waits by polling {Client##{api_request_name}} until successful. An error is
10
+ raised after a configurable number of failed checks.
11
+
12
+ This waiter uses the following defaults:
13
+
14
+ | Configuration | Default |
15
+ |-----------------|------------------------|
16
+ | `#interval` | #{waiter.interval} |
17
+ | `#max_attempts` | #{waiter.max_attempts} |
18
+
19
+ You can modify defaults and register callbacks by passing a block argument.
20
+ @yieldparam [Waiters::Waiter] waiter
21
+ @raise [Waiters::Errors::WaiterFailed]
22
+ @see Client#wait_until
23
+ DOCSTRING
24
+ end
25
+
26
+ def return_type
27
+ [resource_class_name]
28
+ end
29
+
30
+ def return_message
31
+ if @operation.path
32
+ "Returns a copy of this #{resource_class_name} with loaded data."
33
+ else
34
+ "Returns a copy of this #{resource_class_name} that is not loaded."
35
+ end
36
+ end
37
+
38
+ def state
39
+ operation_name.to_s.sub('wait_until_', '')
40
+ end
41
+
42
+ def waiter
43
+ @resource_class.client_class.waiters.waiter(@operation.waiter_name)
44
+ end
45
+
46
+ def api_request
47
+ @resource_class.client_class.api.operation(api_request_name)
48
+ end
49
+
50
+ def api_request_params
51
+ @operation.params
52
+ end
53
+
54
+ def api_request_name
55
+ waiter.send(:operation_name)
56
+ end
57
+
58
+ def option_tags
59
+ []
60
+ end
61
+
62
+ def example_tags
63
+ tag = <<-EXAMPLE.strip
64
+ @example Basic usage
65
+ #{variable_name}.#{operation_name}
66
+
67
+ @example Modify default configuration
68
+ #{variable_name}.#{operation_name} do |w|
69
+ w.interval = 10
70
+ w.max_attempts = 100
71
+ w.before_attempt { |count| ... }
72
+ w.before_wait do { |count, prev_resp| ... }
73
+ end
74
+ EXAMPLE
75
+ YARD::DocstringParser.new.parse(tag).to_docstring.tags
76
+ end
77
+
78
+ end
79
+ end
80
+ end
81
+ end