google-cloud-pubsub 2.23.0 → 3.0.0

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.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +18 -0
  3. data/OVERVIEW.md +188 -144
  4. data/lib/google/cloud/pubsub/admin_clients.rb +116 -0
  5. data/lib/google/cloud/pubsub/async_publisher.rb +9 -9
  6. data/lib/google/cloud/pubsub/batch_publisher.rb +4 -4
  7. data/lib/google/cloud/pubsub/errors.rb +3 -3
  8. data/lib/google/cloud/pubsub/message.rb +8 -8
  9. data/lib/google/cloud/pubsub/{subscriber → message_listener}/enumerator_queue.rb +1 -1
  10. data/lib/google/cloud/pubsub/{subscriber → message_listener}/inventory.rb +2 -4
  11. data/lib/google/cloud/pubsub/{subscriber → message_listener}/sequencer.rb +1 -1
  12. data/lib/google/cloud/pubsub/{subscriber → message_listener}/stream.rb +10 -10
  13. data/lib/google/cloud/pubsub/{subscriber → message_listener}/timed_unary_buffer.rb +1 -1
  14. data/lib/google/cloud/pubsub/message_listener.rb +413 -0
  15. data/lib/google/cloud/pubsub/project.rb +98 -531
  16. data/lib/google/cloud/pubsub/publisher.rb +373 -0
  17. data/lib/google/cloud/pubsub/received_message.rb +44 -39
  18. data/lib/google/cloud/pubsub/service.rb +24 -386
  19. data/lib/google/cloud/pubsub/subscriber.rb +442 -279
  20. data/lib/google/cloud/pubsub/version.rb +1 -1
  21. data/lib/google/cloud/pubsub.rb +8 -15
  22. data/lib/google-cloud-pubsub.rb +5 -4
  23. metadata +9 -17
  24. data/lib/google/cloud/pubsub/policy.rb +0 -188
  25. data/lib/google/cloud/pubsub/retry_policy.rb +0 -88
  26. data/lib/google/cloud/pubsub/schema/list.rb +0 -180
  27. data/lib/google/cloud/pubsub/schema.rb +0 -378
  28. data/lib/google/cloud/pubsub/snapshot/list.rb +0 -178
  29. data/lib/google/cloud/pubsub/snapshot.rb +0 -205
  30. data/lib/google/cloud/pubsub/subscription/list.rb +0 -205
  31. data/lib/google/cloud/pubsub/subscription/push_config.rb +0 -268
  32. data/lib/google/cloud/pubsub/subscription.rb +0 -1467
  33. data/lib/google/cloud/pubsub/topic/list.rb +0 -171
  34. data/lib/google/cloud/pubsub/topic.rb +0 -1100
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module PubSub
19
- VERSION = "2.23.0".freeze
19
+ VERSION = "3.0.0".freeze
20
20
  end
21
21
 
22
22
  Pubsub = PubSub unless const_defined? :Pubsub
@@ -59,9 +59,6 @@ module Google
59
59
  # If the param is nil, uses the default endpoint.
60
60
  # @param [String] emulator_host Pub/Sub emulator host. Optional.
61
61
  # If the param is nil, uses the value of the `emulator_host` config.
62
- # @param [String] project Alias for the `project_id` argument. Deprecated.
63
- # @param [String] keyfile Alias for the `credentials` argument.
64
- # Deprecated.
65
62
  # @param universe_domain [String] A custom universe domain. Optional.
66
63
  #
67
64
  # @return [Google::Cloud::PubSub::Project]
@@ -71,8 +68,8 @@ module Google
71
68
  #
72
69
  # pubsub = Google::Cloud::PubSub.new
73
70
  #
74
- # topic = pubsub.topic "my-topic"
75
- # topic.publish "task completed"
71
+ # publisher = pubsub.publisher "my-topic"
72
+ # publisher.publish "task completed"
76
73
  #
77
74
  def self.new project_id: nil,
78
75
  credentials: nil,
@@ -80,10 +77,8 @@ module Google
80
77
  timeout: nil,
81
78
  universe_domain: nil,
82
79
  endpoint: nil,
83
- emulator_host: nil,
84
- project: nil,
85
- keyfile: nil
86
- project_id ||= project || default_project_id
80
+ emulator_host: nil
81
+ project_id ||= default_project_id
87
82
  scope ||= configure.scope
88
83
  timeout ||= configure.timeout
89
84
  endpoint ||= configure.endpoint
@@ -94,7 +89,7 @@ module Google
94
89
  credentials = :this_channel_is_insecure
95
90
  endpoint = emulator_host
96
91
  else
97
- credentials ||= keyfile || default_credentials(scope: scope)
92
+ credentials ||= default_credentials scope: scope
98
93
  unless credentials.is_a? Google::Auth::Credentials
99
94
  credentials = PubSub::Credentials.new credentials, scope: scope
100
95
  end
@@ -116,12 +111,10 @@ module Google
116
111
  #
117
112
  # The following PubSub configuration parameters are supported:
118
113
  #
119
- # * `project_id` - (String) Identifier for a PubSub project. (The
120
- # parameter `project` is considered deprecated, but may also be used.)
114
+ # * `project_id` - (String) Identifier for a PubSub project.
121
115
  # * `credentials` - (String, Hash, Google::Auth::Credentials) The path to
122
116
  # the keyfile as a String, the contents of the keyfile as a Hash, or a
123
- # Google::Auth::Credentials object. (See {PubSub::Credentials}) (The
124
- # parameter `keyfile` is considered deprecated, but may also be used.)
117
+ # Google::Auth::Credentials object. (See {PubSub::Credentials})
125
118
  # * `scope` - (String, Array<String>) The OAuth 2.0 scopes controlling
126
119
  # the set of resources and operations that the connection can access.
127
120
  # * `quota_project` - (String) The project ID for a project that can be
@@ -133,7 +126,7 @@ module Google
133
126
  # `ENV["PUBSUB_EMULATOR_HOST"]`
134
127
  # * `on_error` - (Proc) A Proc to be run when an error is encountered
135
128
  # on a background thread. The Proc must take the error object as the
136
- # single argument. (See {Subscriber.on_error}.)
129
+ # single argument. (See {MessageListener.on_error}.)
137
130
  #
138
131
  # @return [Google::Cloud::Config] The configuration object the
139
132
  # Google::Cloud::PubSub library uses.
@@ -50,8 +50,9 @@ module Google
50
50
  #
51
51
  # gcloud = Google::Cloud.new
52
52
  # pubsub = gcloud.pubsub
53
- # topic = pubsub.topic "my-topic"
54
- # topic.publish "task completed"
53
+ # topic_admin = pubsub.topic_admin
54
+ # publisher = pubsub.publisher "my-topic"
55
+ # publisher.publish "task completed"
55
56
  #
56
57
  # @example The default scope can be overridden with the `scope` option:
57
58
  # require "google/cloud"
@@ -96,8 +97,8 @@ module Google
96
97
  #
97
98
  # pubsub = Google::Cloud.pubsub
98
99
  #
99
- # topic = pubsub.topic "my-topic"
100
- # topic.publish "task completed"
100
+ # publisher = pubsub.publisher "my-topic"
101
+ # publisher.publish "task completed"
101
102
  #
102
103
  def self.pubsub project_id = nil,
103
104
  credentials = nil,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-cloud-pubsub
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.23.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Moore
@@ -87,6 +87,7 @@ files:
87
87
  - lib/google-cloud-pubsub.rb
88
88
  - lib/google/cloud/pubsub.rb
89
89
  - lib/google/cloud/pubsub/acknowledge_result.rb
90
+ - lib/google/cloud/pubsub/admin_clients.rb
90
91
  - lib/google/cloud/pubsub/async_publisher.rb
91
92
  - lib/google/cloud/pubsub/async_publisher/batch.rb
92
93
  - lib/google/cloud/pubsub/batch_publisher.rb
@@ -95,27 +96,18 @@ files:
95
96
  - lib/google/cloud/pubsub/errors.rb
96
97
  - lib/google/cloud/pubsub/flow_controller.rb
97
98
  - lib/google/cloud/pubsub/message.rb
98
- - lib/google/cloud/pubsub/policy.rb
99
+ - lib/google/cloud/pubsub/message_listener.rb
100
+ - lib/google/cloud/pubsub/message_listener/enumerator_queue.rb
101
+ - lib/google/cloud/pubsub/message_listener/inventory.rb
102
+ - lib/google/cloud/pubsub/message_listener/sequencer.rb
103
+ - lib/google/cloud/pubsub/message_listener/stream.rb
104
+ - lib/google/cloud/pubsub/message_listener/timed_unary_buffer.rb
99
105
  - lib/google/cloud/pubsub/project.rb
100
106
  - lib/google/cloud/pubsub/publish_result.rb
107
+ - lib/google/cloud/pubsub/publisher.rb
101
108
  - lib/google/cloud/pubsub/received_message.rb
102
- - lib/google/cloud/pubsub/retry_policy.rb
103
- - lib/google/cloud/pubsub/schema.rb
104
- - lib/google/cloud/pubsub/schema/list.rb
105
109
  - lib/google/cloud/pubsub/service.rb
106
- - lib/google/cloud/pubsub/snapshot.rb
107
- - lib/google/cloud/pubsub/snapshot/list.rb
108
110
  - lib/google/cloud/pubsub/subscriber.rb
109
- - lib/google/cloud/pubsub/subscriber/enumerator_queue.rb
110
- - lib/google/cloud/pubsub/subscriber/inventory.rb
111
- - lib/google/cloud/pubsub/subscriber/sequencer.rb
112
- - lib/google/cloud/pubsub/subscriber/stream.rb
113
- - lib/google/cloud/pubsub/subscriber/timed_unary_buffer.rb
114
- - lib/google/cloud/pubsub/subscription.rb
115
- - lib/google/cloud/pubsub/subscription/list.rb
116
- - lib/google/cloud/pubsub/subscription/push_config.rb
117
- - lib/google/cloud/pubsub/topic.rb
118
- - lib/google/cloud/pubsub/topic/list.rb
119
111
  - lib/google/cloud/pubsub/version.rb
120
112
  homepage: https://github.com/googleapis/google-cloud-ruby/tree/master/google-cloud-pubsub
121
113
  licenses:
@@ -1,188 +0,0 @@
1
- # Copyright 2016 Google LLC
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # https://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
-
16
- require "google/cloud/errors"
17
-
18
- module Google
19
- module Cloud
20
- module PubSub
21
- ##
22
- # # Policy
23
- #
24
- # Represents a Cloud IAM Policy for the Pub/Sub service.
25
- #
26
- # A common pattern for updating a resource's metadata, such as its Policy,
27
- # is to read the current data from the service, update the data locally,
28
- # and then send the modified data for writing. This pattern may result in
29
- # a conflict if two or more processes attempt the sequence simultaneously.
30
- # IAM solves this problem with the {Google::Cloud::PubSub::Policy#etag}
31
- # property, which is used to verify whether the policy has changed since
32
- # the last request. When you make a request to with an `etag` value, Cloud
33
- # IAM compares the `etag` value in the request with the existing `etag`
34
- # value associated with the policy. It writes the policy only if the
35
- # `etag` values match.
36
- #
37
- # When you update a policy, first read the policy (and its current `etag`)
38
- # from the service, then modify the policy locally, and then write the
39
- # modified policy to the service. See
40
- # {Google::Cloud::PubSub::Topic#policy} and
41
- # {Google::Cloud::PubSub::Topic#policy=}.
42
- #
43
- # @see https://cloud.google.com/iam/docs/managing-policies Managing
44
- # policies
45
- # @see https://cloud.google.com/pubsub/docs/reference/rpc/google.iam.v1#iampolicy
46
- # google.iam.v1.IAMPolicy
47
- #
48
- # @attr [String] etag Used to verify whether the policy has changed since
49
- # the last request. The policy will be written only if the `etag` values
50
- # match.
51
- # @attr [Hash{String => Array<String>}] roles The bindings that associate
52
- # roles with an array of members. See [Understanding
53
- # Roles](https://cloud.google.com/iam/docs/understanding-roles) for a
54
- # listing of primitive and curated roles.
55
- # See [Binding](https://cloud.google.com/pubsub/docs/reference/rpc/google.iam.v1#binding)
56
- # for a listing of values and patterns for members.
57
- #
58
- # @example
59
- # require "google/cloud/pubsub"
60
- #
61
- # pubsub = Google::Cloud::PubSub.new
62
- # topic = pubsub.topic "my-topic"
63
- #
64
- # topic.policy do |p|
65
- # p.remove "roles/owner", "user:owner@example.com"
66
- # p.add "roles/owner", "user:newowner@example.com"
67
- # p.roles["roles/viewer"] = ["allUsers"]
68
- # end
69
- #
70
- class Policy
71
- attr_reader :etag
72
- attr_reader :roles
73
-
74
- ##
75
- # @private Creates a Policy object.
76
- def initialize etag, roles
77
- @etag = etag
78
- @roles = roles
79
- end
80
-
81
- ##
82
- # Convenience method for adding a member to a binding on this policy.
83
- # See [Understanding
84
- # Roles](https://cloud.google.com/iam/docs/understanding-roles) for a
85
- # listing of primitive and curated roles.
86
- # See [Binding](https://cloud.google.com/pubsub/docs/reference/rpc/google.iam.v1#binding)
87
- # for a listing of values and patterns for members.
88
- #
89
- # @param [String] role_name A Cloud IAM role, such as
90
- # `"roles/pubsub.admin"`.
91
- # @param [String] member A Cloud IAM identity, such as
92
- # `"user:owner@example.com"`.
93
- #
94
- # @example
95
- # require "google/cloud/pubsub"
96
- #
97
- # pubsub = Google::Cloud::PubSub.new
98
- # topic = pubsub.topic "my-topic"
99
- #
100
- # topic.policy do |p|
101
- # p.add "roles/owner", "user:newowner@example.com"
102
- # end
103
- #
104
- def add role_name, member
105
- role(role_name) << member
106
- end
107
-
108
- ##
109
- # Convenience method for removing a member from a binding on this
110
- # policy. See [Understanding
111
- # Roles](https://cloud.google.com/iam/docs/understanding-roles) for a
112
- # listing of primitive and curated roles. See
113
- # [Binding](https://cloud.google.com/pubsub/docs/reference/rpc/google.iam.v1#binding)
114
- # for a listing of values and patterns for members.
115
- #
116
- # @param [String] role_name A Cloud IAM role, such as
117
- # `"roles/pubsub.admin"`.
118
- # @param [String] member A Cloud IAM identity, such as
119
- # `"user:owner@example.com"`.
120
- #
121
- # @example
122
- # require "google/cloud/pubsub"
123
- #
124
- # pubsub = Google::Cloud::PubSub.new
125
- # topic = pubsub.topic "my-topic"
126
- #
127
- # topic.policy do |p|
128
- # p.remove "roles/owner", "user:owner@example.com"
129
- # end
130
- #
131
- def remove role_name, member
132
- role(role_name).delete member
133
- end
134
-
135
- ##
136
- # Convenience method returning the array of members bound to a role in
137
- # this policy, or an empty array if no value is present for the role in
138
- # {#roles}. See [Understanding
139
- # Roles](https://cloud.google.com/iam/docs/understanding-roles) for a
140
- # listing of primitive and curated roles. See
141
- # [Binding](https://cloud.google.com/pubsub/docs/reference/rpc/google.iam.v1#binding)
142
- # for a listing of values and patterns for members.
143
- #
144
- # @return [Array<String>] The members strings, or an empty array.
145
- #
146
- # @example
147
- # require "google/cloud/pubsub"
148
- #
149
- # pubsub = Google::Cloud::PubSub.new
150
- # topic = pubsub.topic "my-topic"
151
- #
152
- # topic.policy do |p|
153
- # p.role("roles/viewer") << "user:viewer@example.com"
154
- # end
155
- #
156
- def role role_name
157
- roles[role_name] ||= []
158
- end
159
-
160
- ##
161
- # @private Convert the Policy to a Google::Iam::V1::Policy object.
162
- def to_grpc
163
- Google::Iam::V1::Policy.new(
164
- etag: etag,
165
- bindings: roles.keys.map do |role_name|
166
- next if roles[role_name].empty?
167
- Google::Iam::V1::Binding.new(
168
- role: role_name,
169
- members: roles[role_name]
170
- )
171
- end.compact
172
- )
173
- end
174
-
175
- ##
176
- # @private New Policy from a Google::Iam::V1::Policy object.
177
- def self.from_grpc grpc
178
- roles = grpc.bindings.each_with_object({}) do |binding, memo|
179
- memo[binding.role] = binding.members.to_a
180
- end
181
- new grpc.etag, roles
182
- end
183
- end
184
- end
185
-
186
- Pubsub = PubSub unless const_defined? :Pubsub
187
- end
188
- end
@@ -1,88 +0,0 @@
1
- # Copyright 2016 Google LLC
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # https://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
-
16
- require "google/cloud/errors"
17
-
18
- module Google
19
- module Cloud
20
- module PubSub
21
- ##
22
- # # RetryPolicy
23
- #
24
- # An immutable Retry Policy value object that specifies how Cloud Pub/Sub retries message delivery.
25
- #
26
- # Retry delay will be exponential based on provided minimum and maximum backoffs. (See [Exponential
27
- # backoff](https://en.wikipedia.org/wiki/Exponential_backoff).)
28
- #
29
- # Retry Policy will be triggered on NACKs or acknowledgement deadline exceeded events for a given message.
30
- #
31
- # Retry Policy is implemented on a best effort basis. At times, the delay between consecutive deliveries may not
32
- # match the configuration. That is, delay can be more or less than configured backoff.
33
- #
34
- # @attr [Numeric] minimum_backoff The minimum delay between consecutive deliveries of a given message. Value
35
- # should be between 0 and 600 seconds. The default value is 10 seconds.
36
- # @attr [Numeric] maximum_backoff The maximum delay between consecutive deliveries of a given message. Value
37
- # should be between 0 and 600 seconds. The default value is 600 seconds.
38
- #
39
- # @example
40
- # require "google/cloud/pubsub"
41
- #
42
- # pubsub = Google::Cloud::PubSub.new
43
- #
44
- # sub = pubsub.subscription "my-topic-sub"
45
- #
46
- # sub.retry_policy = Google::Cloud::PubSub::RetryPolicy.new minimum_backoff: 5, maximum_backoff: 300
47
- #
48
- # sub.retry_policy.minimum_backoff #=> 5
49
- # sub.retry_policy.maximum_backoff #=> 300
50
- #
51
- class RetryPolicy
52
- attr_reader :minimum_backoff
53
- attr_reader :maximum_backoff
54
-
55
- ##
56
- # Creates a new, immutable RetryPolicy value object.
57
- #
58
- # @attr [Numeric, nil] minimum_backoff The minimum delay between consecutive deliveries of a given message.
59
- # Value should be between 0 and 600 seconds. If `nil` is provided, the default value is 10 seconds.
60
- # @attr [Numeric, nil] maximum_backoff The maximum delay between consecutive deliveries of a given message.
61
- # Value should be between 0 and 600 seconds. If `nil` is provided, the default value is 600 seconds.
62
- #
63
- def initialize minimum_backoff: nil, maximum_backoff: nil
64
- @minimum_backoff = minimum_backoff
65
- @maximum_backoff = maximum_backoff
66
- end
67
-
68
- ##
69
- # @private Convert the RetryPolicy to a Google::Cloud::PubSub::V1::RetryPolicy object.
70
- def to_grpc
71
- Google::Cloud::PubSub::V1::RetryPolicy.new(
72
- minimum_backoff: Convert.number_to_duration(minimum_backoff),
73
- maximum_backoff: Convert.number_to_duration(maximum_backoff)
74
- )
75
- end
76
-
77
- ##
78
- # @private New RetryPolicy from a Google::Cloud::PubSub::V1::RetryPolicy object.
79
- def self.from_grpc grpc
80
- new(
81
- minimum_backoff: Convert.duration_to_number(grpc.minimum_backoff),
82
- maximum_backoff: Convert.duration_to_number(grpc.maximum_backoff)
83
- )
84
- end
85
- end
86
- end
87
- end
88
- end
@@ -1,180 +0,0 @@
1
- # Copyright 2021 Google LLC
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # https://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
-
16
- require "delegate"
17
-
18
- module Google
19
- module Cloud
20
- module PubSub
21
- class Schema
22
- ##
23
- # Schema::List is a special case Array with additional values.
24
- class List < DelegateClass(::Array)
25
- ##
26
- # If not empty, indicates that there are more schemas
27
- # that match the request and this value should be passed to
28
- # the next {Google::Cloud::PubSub::Project#schemas} to continue.
29
- attr_accessor :token
30
-
31
- ##
32
- # @private Create a new Schema::List with an array of values.
33
- def initialize arr = []
34
- @prefix = nil
35
- @token = nil
36
- @view = nil
37
- @max = nil
38
- super arr
39
- end
40
-
41
- ##
42
- # Whether there a next page of schemas.
43
- #
44
- # @return [Boolean]
45
- #
46
- # @example
47
- # require "google/cloud/pubsub"
48
- #
49
- # pubsub = Google::Cloud::PubSub.new
50
- #
51
- # schemas = pubsub.schemas
52
- # if schemas.next?
53
- # next_schemas = schemas.next
54
- # end
55
- #
56
- def next?
57
- !token.nil?
58
- end
59
-
60
- ##
61
- # Retrieve the next page of schemas.
62
- #
63
- # @return [Schema::List]
64
- #
65
- # @example
66
- # require "google/cloud/pubsub"
67
- #
68
- # pubsub = Google::Cloud::PubSub.new
69
- #
70
- # schemas = pubsub.schemas
71
- # if schemas.next?
72
- # next_schemas = schemas.next
73
- # end
74
- #
75
- def next
76
- return nil unless next?
77
- ensure_service!
78
- next_schemas
79
- end
80
-
81
- ##
82
- # Retrieves remaining results by repeatedly invoking {#next} until
83
- # {#next?} returns `false`. Calls the given block once for each
84
- # result, which is passed as the argument to the block.
85
- #
86
- # An Enumerator is returned if no block is given.
87
- #
88
- # This method will make repeated API calls until all remaining results
89
- # are retrieved. (Unlike `#each`, for example, which merely iterates
90
- # over the results returned by a single API call.) Use with caution.
91
- #
92
- # @param [Integer] request_limit The upper limit of API requests to
93
- # make to load all schemas. Default is no limit.
94
- # @yield [schema] The block for accessing each schema.
95
- # @yieldparam [Schema] schema The schema object.
96
- #
97
- # @return [Enumerator]
98
- #
99
- # @example Iterating each schema by passing a block:
100
- # require "google/cloud/pubsub"
101
- #
102
- # pubsub = Google::Cloud::PubSub.new
103
- #
104
- # schemas = pubsub.schemas
105
- # schemas.all do |schema|
106
- # puts schema.name
107
- # end
108
- #
109
- # @example Using the enumerator by not passing a block:
110
- # require "google/cloud/pubsub"
111
- #
112
- # pubsub = Google::Cloud::PubSub.new
113
- #
114
- # schemas = pubsub.schemas
115
- # all_names = schemas.all.map do |schema|
116
- # schema.name
117
- # end
118
- #
119
- # @example Limit the number of API calls made:
120
- # require "google/cloud/pubsub"
121
- #
122
- # pubsub = Google::Cloud::PubSub.new
123
- #
124
- # schemas = pubsub.schemas
125
- # schemas.all(request_limit: 10) do |schema|
126
- # puts schema.name
127
- # end
128
- #
129
- def all request_limit: nil, &block
130
- request_limit = request_limit.to_i if request_limit
131
- return enum_for :all, request_limit: request_limit unless block_given?
132
- results = self
133
- loop do
134
- results.each(&block)
135
- if request_limit
136
- request_limit -= 1
137
- break if request_limit.negative?
138
- end
139
- break unless results.next?
140
- results = results.next
141
- end
142
- end
143
-
144
- ##
145
- # @private New Schemas::List from a
146
- # Google::Cloud::PubSub::V1::ListSchemasRequest object.
147
- def self.from_grpc grpc_list, service, view, max = nil
148
- subs = new(Array(grpc_list.schemas).map do |grpc|
149
- Schema.from_grpc grpc, service
150
- end)
151
- token = grpc_list.next_page_token
152
- token = nil if token == "".freeze
153
- subs.instance_variable_set :@token, token
154
- subs.instance_variable_set :@service, service
155
- subs.instance_variable_set :@view, view
156
- subs.instance_variable_set :@max, max
157
- subs
158
- end
159
-
160
- protected
161
-
162
- ##
163
- # @private Raise an error unless an active connection to the service
164
- # is available.
165
- def ensure_service!
166
- raise "Must have active connection to service" unless @service
167
- end
168
-
169
- def next_schemas
170
- options = { prefix: @prefix, token: @token, max: @max }
171
- grpc = @service.list_schemas @view, options
172
- self.class.from_grpc grpc, @service, @view, @max
173
- end
174
- end
175
- end
176
- end
177
-
178
- Pubsub = PubSub unless const_defined? :Pubsub
179
- end
180
- end