aws-sdk-resources 2.11.549
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/aws-sdk-resources.rb +91 -0
- data/lib/aws-sdk-resources/batch.rb +143 -0
- data/lib/aws-sdk-resources/builder.rb +85 -0
- data/lib/aws-sdk-resources/builder_sources.rb +105 -0
- data/lib/aws-sdk-resources/collection.rb +107 -0
- data/lib/aws-sdk-resources/definition.rb +331 -0
- data/lib/aws-sdk-resources/documenter.rb +70 -0
- data/lib/aws-sdk-resources/documenter/base_operation_documenter.rb +279 -0
- data/lib/aws-sdk-resources/documenter/data_operation_documenter.rb +25 -0
- data/lib/aws-sdk-resources/documenter/has_many_operation_documenter.rb +69 -0
- data/lib/aws-sdk-resources/documenter/has_operation_documenter.rb +66 -0
- data/lib/aws-sdk-resources/documenter/operation_documenter.rb +20 -0
- data/lib/aws-sdk-resources/documenter/resource_operation_documenter.rb +53 -0
- data/lib/aws-sdk-resources/documenter/waiter_operation_documenter.rb +77 -0
- data/lib/aws-sdk-resources/errors.rb +15 -0
- data/lib/aws-sdk-resources/operation_methods.rb +83 -0
- data/lib/aws-sdk-resources/operations.rb +280 -0
- data/lib/aws-sdk-resources/options.rb +17 -0
- data/lib/aws-sdk-resources/request.rb +39 -0
- data/lib/aws-sdk-resources/request_params.rb +140 -0
- data/lib/aws-sdk-resources/resource.rb +243 -0
- data/lib/aws-sdk-resources/services/ec2.rb +21 -0
- data/lib/aws-sdk-resources/services/ec2/instance.rb +29 -0
- data/lib/aws-sdk-resources/services/iam.rb +19 -0
- data/lib/aws-sdk-resources/services/s3.rb +20 -0
- data/lib/aws-sdk-resources/services/s3/bucket.rb +131 -0
- data/lib/aws-sdk-resources/services/s3/encryption.rb +21 -0
- data/lib/aws-sdk-resources/services/s3/encryption/client.rb +369 -0
- data/lib/aws-sdk-resources/services/s3/encryption/decrypt_handler.rb +174 -0
- data/lib/aws-sdk-resources/services/s3/encryption/default_cipher_provider.rb +63 -0
- data/lib/aws-sdk-resources/services/s3/encryption/default_key_provider.rb +38 -0
- data/lib/aws-sdk-resources/services/s3/encryption/encrypt_handler.rb +50 -0
- data/lib/aws-sdk-resources/services/s3/encryption/errors.rb +13 -0
- data/lib/aws-sdk-resources/services/s3/encryption/io_auth_decrypter.rb +56 -0
- data/lib/aws-sdk-resources/services/s3/encryption/io_decrypter.rb +29 -0
- data/lib/aws-sdk-resources/services/s3/encryption/io_encrypter.rb +69 -0
- data/lib/aws-sdk-resources/services/s3/encryption/key_provider.rb +29 -0
- data/lib/aws-sdk-resources/services/s3/encryption/kms_cipher_provider.rb +71 -0
- data/lib/aws-sdk-resources/services/s3/encryption/materials.rb +58 -0
- data/lib/aws-sdk-resources/services/s3/encryption/utils.rb +79 -0
- data/lib/aws-sdk-resources/services/s3/file_downloader.rb +169 -0
- data/lib/aws-sdk-resources/services/s3/file_part.rb +75 -0
- data/lib/aws-sdk-resources/services/s3/file_uploader.rb +58 -0
- data/lib/aws-sdk-resources/services/s3/multipart_file_uploader.rb +187 -0
- data/lib/aws-sdk-resources/services/s3/multipart_upload.rb +42 -0
- data/lib/aws-sdk-resources/services/s3/multipart_upload_error.rb +16 -0
- data/lib/aws-sdk-resources/services/s3/object.rb +290 -0
- data/lib/aws-sdk-resources/services/s3/object_copier.rb +99 -0
- data/lib/aws-sdk-resources/services/s3/object_multipart_copier.rb +180 -0
- data/lib/aws-sdk-resources/services/s3/object_summary.rb +73 -0
- data/lib/aws-sdk-resources/services/s3/presigned_post.rb +651 -0
- data/lib/aws-sdk-resources/services/sns.rb +7 -0
- data/lib/aws-sdk-resources/services/sns/message_verifier.rb +171 -0
- data/lib/aws-sdk-resources/services/sqs.rb +7 -0
- data/lib/aws-sdk-resources/services/sqs/queue_poller.rb +521 -0
- data/lib/aws-sdk-resources/source.rb +39 -0
- metadata +118 -0
@@ -0,0 +1,25 @@
|
|
1
|
+
module Aws
|
2
|
+
module Resources
|
3
|
+
class Documenter
|
4
|
+
class DataOperationDocumenter < BaseOperationDocumenter
|
5
|
+
|
6
|
+
def return_type
|
7
|
+
if plural?
|
8
|
+
"Array<#{path_type}>"
|
9
|
+
else
|
10
|
+
path_type
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def return_tag
|
15
|
+
tag("@return [#{return_type}]")
|
16
|
+
end
|
17
|
+
|
18
|
+
def plural?
|
19
|
+
!!@operation.path.match(/\[/)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Aws
|
2
|
+
module Resources
|
3
|
+
class Documenter
|
4
|
+
class HasManyOperationDocumenter < 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_tag
|
16
|
+
tag("@return [Collection<#{target_resource_class_name}>]")
|
17
|
+
end
|
18
|
+
|
19
|
+
def example_tags
|
20
|
+
tags = super
|
21
|
+
tags << enumerate_example_tag
|
22
|
+
tags << enumerate_with_limit_example_tag
|
23
|
+
tags << batch_examples_tag if target_resource_batches?
|
24
|
+
tags
|
25
|
+
end
|
26
|
+
|
27
|
+
def enumerate_example_tag
|
28
|
+
tag(<<-EXAMPLE.strip)
|
29
|
+
@example Enumerating {#{target_resource_class_name}} resources.
|
30
|
+
#{variable_name}.#{@operation_name}.each do |#{target_resource_class_name.downcase}|
|
31
|
+
# yields each #{target_resource_class_name.downcase}
|
32
|
+
end
|
33
|
+
EXAMPLE
|
34
|
+
end
|
35
|
+
|
36
|
+
def enumerate_with_limit_example_tag
|
37
|
+
tag(<<-EXAMPLE.strip)
|
38
|
+
@example Enumerating {#{target_resource_class_name}} resources with a limit.
|
39
|
+
#{variable_name}.#{@operation_name}.limit(10).each do |#{target_resource_class_name.downcase}|
|
40
|
+
# yields at most 10 #{@operation_name}
|
41
|
+
end
|
42
|
+
EXAMPLE
|
43
|
+
end
|
44
|
+
|
45
|
+
def batch_examples_tag
|
46
|
+
example = []
|
47
|
+
example << "@example Batch operations callable on the returned collection"
|
48
|
+
target_resource_batch_operations.each do |name, operation|
|
49
|
+
if operation.respond_to?(:request)
|
50
|
+
example << ""
|
51
|
+
example << " # calls Client##{operation.request.method_name} on each batch"
|
52
|
+
example << " #{variable_name}.#{@operation_name}.#{name}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
tag(example.join("\n"))
|
56
|
+
end
|
57
|
+
|
58
|
+
def target_resource_batches?
|
59
|
+
target_resource_batch_operations.count > 0
|
60
|
+
end
|
61
|
+
|
62
|
+
def target_resource_batch_operations
|
63
|
+
target_resource_class.batch_operations
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Aws
|
2
|
+
module Resources
|
3
|
+
class Documenter
|
4
|
+
class HasOperationDocumenter < BaseOperationDocumenter
|
5
|
+
|
6
|
+
def return_tag
|
7
|
+
if plural?
|
8
|
+
type = "Array<#{target_resource_class_name}>"
|
9
|
+
else
|
10
|
+
type = target_resource_class_name
|
11
|
+
end
|
12
|
+
type += ',nil' if can_return_nil?
|
13
|
+
tag("@return [#{type}]")
|
14
|
+
end
|
15
|
+
|
16
|
+
def parameters
|
17
|
+
if argument?
|
18
|
+
arguments.map { |arg| [argument_name(arg), nil] }
|
19
|
+
else
|
20
|
+
[]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def tags
|
25
|
+
tags = super
|
26
|
+
if argument?
|
27
|
+
arguments.each do |arg|
|
28
|
+
tag = "@param [String] #{argument_name(arg)} "
|
29
|
+
tag << "The {#{target_resource_class_name}##{argument_name(arg)}} "
|
30
|
+
tag << "identifier."
|
31
|
+
tags += YARD::DocstringParser.new.parse(tag).to_docstring.tags
|
32
|
+
end
|
33
|
+
end
|
34
|
+
tags
|
35
|
+
end
|
36
|
+
|
37
|
+
def plural?
|
38
|
+
@operation.builder.plural?
|
39
|
+
end
|
40
|
+
|
41
|
+
def argument?
|
42
|
+
@operation.arity > 0
|
43
|
+
end
|
44
|
+
|
45
|
+
def can_return_nil?
|
46
|
+
data_member
|
47
|
+
end
|
48
|
+
|
49
|
+
def data_member
|
50
|
+
builder.sources.find { |s| BuilderSources::DataMember === s }
|
51
|
+
end
|
52
|
+
|
53
|
+
def arguments
|
54
|
+
builder.sources.select do |source|
|
55
|
+
BuilderSources::Argument === source
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def argument_name(argument)
|
60
|
+
argument.target.to_s
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Aws
|
2
|
+
module Resources
|
3
|
+
class Documenter
|
4
|
+
class OperationDocumenter < BaseOperationDocumenter
|
5
|
+
|
6
|
+
def docstring
|
7
|
+
@api_request.documentation
|
8
|
+
end
|
9
|
+
|
10
|
+
def return_tag
|
11
|
+
@yard_client_operation.tags.each do |tag|
|
12
|
+
return tag if tag.tag_name == 'return'
|
13
|
+
end
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,53 @@
|
|
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 return_tag
|
19
|
+
if plural?
|
20
|
+
tag("@return [Array<#{target_resource_class_name}>]")
|
21
|
+
else
|
22
|
+
tag("@return [#{target_resource_class_name}]")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def example_tags
|
27
|
+
id = target_resource_class.identifiers.last.to_s
|
28
|
+
idv = target_resource_class_name.downcase + '-' + id.gsub('_', '-')
|
29
|
+
example = []
|
30
|
+
example << "@example Basic usage"
|
31
|
+
example << " #{resp_variable} = #{variable_name}.#{operation_name}(options)"
|
32
|
+
if plural?
|
33
|
+
example << " #{resp_variable}.map(&:#{id})"
|
34
|
+
example << " #=> [#{idv.inspect}, ...]"
|
35
|
+
else
|
36
|
+
example << " #{resp_variable}.#{id}"
|
37
|
+
example << " #=> #{idv.inspect}"
|
38
|
+
end
|
39
|
+
super + [tag(example.join("\n"))]
|
40
|
+
end
|
41
|
+
|
42
|
+
def resp_variable
|
43
|
+
if plural?
|
44
|
+
target_resource_class_name.downcase + 's'
|
45
|
+
else
|
46
|
+
target_resource_class_name.downcase
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,77 @@
|
|
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
|
+
| `#delay` | #{waiter.delay} |
|
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_tag
|
27
|
+
tag("@return [#{resource_class_name}] #{return_message}")
|
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_name
|
51
|
+
waiter.poller.operation_name
|
52
|
+
end
|
53
|
+
|
54
|
+
def option_tags
|
55
|
+
[]
|
56
|
+
end
|
57
|
+
|
58
|
+
def example_tags
|
59
|
+
example = <<-EXAMPLE.strip
|
60
|
+
@example Basic usage
|
61
|
+
#{variable_name}.#{operation_name}
|
62
|
+
|
63
|
+
@example Modify default configuration
|
64
|
+
#{variable_name}.#{operation_name} do |w|
|
65
|
+
w.interval = 10
|
66
|
+
w.max_attempts = 100
|
67
|
+
w.before_attempt { |count| ... }
|
68
|
+
w.before_wait do { |count, prev_resp| ... }
|
69
|
+
end
|
70
|
+
EXAMPLE
|
71
|
+
[tag(example)]
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module Aws
|
2
|
+
module Resources
|
3
|
+
module OperationMethods
|
4
|
+
|
5
|
+
# @param [Symbol] name
|
6
|
+
# @return [Operation] Returns the named operation.
|
7
|
+
# @raise [Errors::UnknownOperationError]
|
8
|
+
def operation(name)
|
9
|
+
@operations[name.to_sym] or
|
10
|
+
raise Errors::UnknownOperationError.new(name)
|
11
|
+
end
|
12
|
+
|
13
|
+
# @param [Symbol] method_name
|
14
|
+
# @param [Operation] operation
|
15
|
+
# @return [void]
|
16
|
+
def add_operation(method_name, operation = nil, &definition)
|
17
|
+
operation = definition if block_given?
|
18
|
+
safe_define_method(method_name) do |*args, &block|
|
19
|
+
operation.call(resource:self, args:args, block:block)
|
20
|
+
end
|
21
|
+
@operations[method_name.to_sym] = operation
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [Hash]
|
25
|
+
def operations(&block)
|
26
|
+
@operations.dup
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [Array<Symbol>]
|
30
|
+
def operation_names
|
31
|
+
@operations.keys.sort
|
32
|
+
end
|
33
|
+
|
34
|
+
# @param [Symbol] name
|
35
|
+
# @return [Operation] Returns the named batch operation.
|
36
|
+
# @raise [Errors::UnknownOperationError]
|
37
|
+
def batch_operation(name)
|
38
|
+
@batch_operations[name.to_sym] or
|
39
|
+
raise Errors::UnknownOperationError.new(name)
|
40
|
+
end
|
41
|
+
|
42
|
+
# @param [Symbol] method_name
|
43
|
+
# @param [Operation] operation
|
44
|
+
# @return [void]
|
45
|
+
def add_batch_operation(method_name, operation = nil, &definition)
|
46
|
+
operation = definition if block_given?
|
47
|
+
@batch_operations[method_name.to_sym] = operation
|
48
|
+
end
|
49
|
+
|
50
|
+
# @return [Hash]
|
51
|
+
def batch_operations(&block)
|
52
|
+
@batch_operations.dup
|
53
|
+
end
|
54
|
+
|
55
|
+
# @return [Array<Symbol>]
|
56
|
+
def batch_operation_names
|
57
|
+
@batch_operations.keys.sort
|
58
|
+
end
|
59
|
+
|
60
|
+
# @api private
|
61
|
+
def inherited(subclass)
|
62
|
+
subclass.send(:instance_variable_set, "@operations", {})
|
63
|
+
subclass.send(:instance_variable_set, "@batch_operations", {})
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def safe_define_method(method_name, &block)
|
69
|
+
if
|
70
|
+
instance_methods.include?(method_name.to_sym) &&
|
71
|
+
ENV['AWS_SDK_SAFE_DEFINE']
|
72
|
+
then
|
73
|
+
msg = "unable to define method #{name}##{method_name}, "
|
74
|
+
msg << "method already exists"
|
75
|
+
raise Errors::DefinitionError, msg
|
76
|
+
else
|
77
|
+
define_method(method_name, &block)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,280 @@
|
|
1
|
+
module Aws
|
2
|
+
module Resources
|
3
|
+
module Operations
|
4
|
+
|
5
|
+
# Base class for operations. An operation is any object that responds
|
6
|
+
# to `#call` receiving a hash of options including:
|
7
|
+
#
|
8
|
+
# * `:resource` - The resource object the operation is invoked against.
|
9
|
+
# * `:args` - An array of arguments given by the caller
|
10
|
+
# * `:block` - An optional block argument
|
11
|
+
#
|
12
|
+
class Base
|
13
|
+
|
14
|
+
include Options
|
15
|
+
|
16
|
+
def initialize(options = {})
|
17
|
+
@source = options[:source]
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [Source, nil]
|
21
|
+
attr_reader :source
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
# Makes an API request using the resource client, returning the client
|
26
|
+
# response. Most operation classes extend this basic operation.
|
27
|
+
class Operation < Base
|
28
|
+
|
29
|
+
# @option options [required, Request] :request
|
30
|
+
def initialize(options = {})
|
31
|
+
@request = option(:request, options)
|
32
|
+
super
|
33
|
+
end
|
34
|
+
|
35
|
+
# @return [Request]
|
36
|
+
attr_reader :request
|
37
|
+
|
38
|
+
# @option (see Base#call)
|
39
|
+
# @return [Seahorse::Client::Response]
|
40
|
+
def call(options)
|
41
|
+
@request.call(options)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
class LoadOperation < Operation
|
47
|
+
|
48
|
+
# @option options [required, Request] :request
|
49
|
+
# @option options [required, String<JMESPath>] :path
|
50
|
+
def initialize(options = {})
|
51
|
+
@path = option(:path, options)
|
52
|
+
super
|
53
|
+
end
|
54
|
+
|
55
|
+
# @return [String<JMESPath>]
|
56
|
+
attr_reader :path
|
57
|
+
|
58
|
+
# @option (see Base#call)
|
59
|
+
# @return [Object] Returns the value resolved to by {#path}.
|
60
|
+
def call(options)
|
61
|
+
extract(super)
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def extract(resp)
|
67
|
+
JMESPath.search(@path, resp.data)
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
class ResourceOperation < Operation
|
73
|
+
|
74
|
+
# @option options [required, Request] :request
|
75
|
+
# @option options [required, Builder] :builder
|
76
|
+
def initialize(options = {})
|
77
|
+
@builder = option(:builder, options)
|
78
|
+
super
|
79
|
+
end
|
80
|
+
|
81
|
+
# @return [Builder]
|
82
|
+
attr_reader :builder
|
83
|
+
|
84
|
+
# @option (see Base#call)
|
85
|
+
# @return [Resource, Array<Resource>]
|
86
|
+
def call(options)
|
87
|
+
@builder.build(options.merge(response:super))
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
class HasManyOperation < ResourceOperation
|
93
|
+
|
94
|
+
# @option options [required, Request] :request
|
95
|
+
# @option options [required, Builder] :builder
|
96
|
+
# @option options [Symbol] :limit_key
|
97
|
+
def initialize(options)
|
98
|
+
@limit_key = options[:limit_key]
|
99
|
+
super
|
100
|
+
end
|
101
|
+
|
102
|
+
# @return [Builder]
|
103
|
+
attr_reader :builder
|
104
|
+
|
105
|
+
# @return [Symbol, nil]
|
106
|
+
attr_reader :limit_key
|
107
|
+
|
108
|
+
# @option (see Base#call)
|
109
|
+
# @return [Collection]
|
110
|
+
def call(options)
|
111
|
+
validate_args!(options)
|
112
|
+
Collection.new(self, options)
|
113
|
+
end
|
114
|
+
|
115
|
+
# @api private
|
116
|
+
# @return [Enumerator<Batch>]
|
117
|
+
def batches(options, &block)
|
118
|
+
if options[:limit]
|
119
|
+
enum_for(:limited_batches, options[:limit], options, &block)
|
120
|
+
else
|
121
|
+
enum_for(:all_batches, options, &block)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
private
|
126
|
+
|
127
|
+
def validate_args!(options)
|
128
|
+
args = options[:args]
|
129
|
+
unless args.count == 0 || args.count == 1
|
130
|
+
msg = "wrong number of arguments (given #{args.count}, expected 0..1)"
|
131
|
+
raise ArgumentError, msg
|
132
|
+
end
|
133
|
+
unless args[0].nil? || Hash === args[0]
|
134
|
+
raise ArgumentError, "expected Hash, got #{args[0].class}"
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def all_batches(options, &block)
|
139
|
+
resp = @request.call(options)
|
140
|
+
if resp.respond_to?(:each)
|
141
|
+
resp.each do |response|
|
142
|
+
yield(@builder.build(options.merge(response:response)))
|
143
|
+
end
|
144
|
+
else
|
145
|
+
yield(@builder.build(options.merge(response:resp)))
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def limited_batches(limit, options, &block)
|
150
|
+
remaining = limit
|
151
|
+
all_batches(options) do |batch|
|
152
|
+
if batch.size < remaining
|
153
|
+
yield(batch)
|
154
|
+
remaining -= batch.size
|
155
|
+
else
|
156
|
+
yield(batch.first(remaining))
|
157
|
+
return
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
163
|
+
|
164
|
+
class HasOperation < Base
|
165
|
+
|
166
|
+
# @option options [required, Builder] :builder
|
167
|
+
def initialize(options = {})
|
168
|
+
@builder = option(:builder, options)
|
169
|
+
super
|
170
|
+
end
|
171
|
+
|
172
|
+
# @return [Builder]
|
173
|
+
attr_reader :builder
|
174
|
+
|
175
|
+
# @option (see Base#call)
|
176
|
+
# @return [Resource]
|
177
|
+
def call(options)
|
178
|
+
if argc(options) == arity
|
179
|
+
@builder.build(options)
|
180
|
+
else
|
181
|
+
msg = "wrong number of arguments (#{argc(options)} for #{arity})"
|
182
|
+
raise ArgumentError, msg
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def arity
|
187
|
+
@builder.sources.count { |s| BuilderSources::Argument === s }
|
188
|
+
end
|
189
|
+
|
190
|
+
private
|
191
|
+
|
192
|
+
def argc(options)
|
193
|
+
(options[:args] || []).count
|
194
|
+
end
|
195
|
+
|
196
|
+
end
|
197
|
+
|
198
|
+
class WaiterOperation < Base
|
199
|
+
|
200
|
+
include Options
|
201
|
+
|
202
|
+
def initialize(options = {})
|
203
|
+
@waiter_name = option(:waiter_name, options)
|
204
|
+
@waiter_params = option(:waiter_params, options)
|
205
|
+
@path = options[:path]
|
206
|
+
super
|
207
|
+
end
|
208
|
+
|
209
|
+
# @return [Symbol]
|
210
|
+
attr_reader :waiter_name
|
211
|
+
|
212
|
+
# @return [Array<RequestParams::Base>]
|
213
|
+
attr_reader :waiter_params
|
214
|
+
|
215
|
+
# @return [String<JMESPathExpression>, nil]
|
216
|
+
attr_reader :path
|
217
|
+
|
218
|
+
# @option options [required,Resource] :resource
|
219
|
+
# @option options [required,Array<Mixed>] :args
|
220
|
+
def call(options)
|
221
|
+
|
222
|
+
resource = options[:resource]
|
223
|
+
|
224
|
+
params_hash = options[:args].first || {}
|
225
|
+
@waiter_params.each do |param|
|
226
|
+
param.apply(params_hash, options)
|
227
|
+
end
|
228
|
+
|
229
|
+
resp = resource.client.wait_until(@waiter_name, params_hash, &options[:block])
|
230
|
+
|
231
|
+
resource_opts = resource.identifiers.dup
|
232
|
+
if @path && resp.respond_to?(:data)
|
233
|
+
resource_opts[:data] = JMESPath.search(@path, resp.data)
|
234
|
+
end
|
235
|
+
resource_opts[:client] = resource.client
|
236
|
+
resource.class.new(resource_opts)
|
237
|
+
end
|
238
|
+
|
239
|
+
end
|
240
|
+
|
241
|
+
# @api private
|
242
|
+
class DeprecatedOperation
|
243
|
+
|
244
|
+
def initialize(options = {})
|
245
|
+
@name = options[:name]
|
246
|
+
@deprecated_name = options[:deprecated_name]
|
247
|
+
@resource_class = options[:resource_class]
|
248
|
+
@operation = @resource_class.batch_operation(@name)
|
249
|
+
@warned = false
|
250
|
+
end
|
251
|
+
|
252
|
+
def call(*args)
|
253
|
+
unless @warned
|
254
|
+
@warned = true
|
255
|
+
warn(deprecation_warning)
|
256
|
+
end
|
257
|
+
@operation.call(*args)
|
258
|
+
end
|
259
|
+
|
260
|
+
private
|
261
|
+
|
262
|
+
def deprecation_warning
|
263
|
+
"DEPRECATION WARNING: called deprecated batch method " +
|
264
|
+
"`##{@deprecated_name}` on a batch of `#{@resource_class.name}` " +
|
265
|
+
"objects; use `##{@name}` instead"
|
266
|
+
end
|
267
|
+
|
268
|
+
class << self
|
269
|
+
|
270
|
+
def define(options = {})
|
271
|
+
klass = options[:resource_class]
|
272
|
+
deprecated_name = options[:deprecated_name]
|
273
|
+
klass.add_batch_operation(deprecated_name, new(options))
|
274
|
+
end
|
275
|
+
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
end
|
280
|
+
end
|