Class: Gcloud::Pubsub::Subscription::List
- Inherits:
-
Array
- Object
- Array
- Gcloud::Pubsub::Subscription::List
- Defined in:
- lib/gcloud/pubsub/subscription/list.rb
Overview
Subscription::List is a special case Array with additional values.
Instance Attribute Summary collapse
-
#token ⇒ Object
If not empty, indicates that there are more subscriptions that match the request and this value should be passed to the next Topic#subscriptions to continue.
Class Method Summary collapse
-
.from_grpc(grpc_list, service, max = nil) ⇒ Object
Google::Pubsub::V1::ListSubscriptionsRequest object.
-
.from_topic_grpc(grpc_list, service, topic, max = nil) ⇒ Object
Google::Pubsub::V1::ListTopicSubscriptionsResponse object.
Instance Method Summary collapse
- #all(request_limit: nil) {|subscription| ... } ⇒ Enumerator
-
#initialize(arr = []) ⇒ List
constructor
A new instance of List.
-
#next ⇒ Subscription::List
Retrieve the next page of subscriptions.
-
#next? ⇒ Boolean
Whether there a next page of subscriptions.
Constructor Details
#initialize(arr = []) ⇒ List
Returns a new instance of List.
32 33 34 35 36 37 38 |
# File 'lib/gcloud/pubsub/subscription/list.rb', line 32 def initialize arr = [] @topic = nil @prefix = nil @token = nil @max = nil super arr end |
Instance Attribute Details
#token ⇒ Object
If not empty, indicates that there are more subscriptions that match the request and this value should be passed to the next Topic#subscriptions to continue.
28 29 30 |
# File 'lib/gcloud/pubsub/subscription/list.rb', line 28 def token @token end |
Class Method Details
.from_grpc(grpc_list, service, max = nil) ⇒ Object
Google::Pubsub::V1::ListSubscriptionsRequest object.
157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/gcloud/pubsub/subscription/list.rb', line 157 def self.from_grpc grpc_list, service, max = nil subs = new(Array(grpc_list.subscriptions).map do |grpc| Subscription.from_grpc grpc, service end) token = grpc_list.next_page_token token = nil if token == "" subs.instance_variable_set "@token", token subs.instance_variable_set "@service", service subs.instance_variable_set "@max", max subs end |
.from_topic_grpc(grpc_list, service, topic, max = nil) ⇒ Object
Google::Pubsub::V1::ListTopicSubscriptionsResponse object.
172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/gcloud/pubsub/subscription/list.rb', line 172 def self.from_topic_grpc grpc_list, service, topic, max = nil subs = new(Array(grpc_list.subscriptions).map do |grpc| Subscription.new_lazy grpc, service end) token = grpc_list.next_page_token token = nil if token == "" subs.instance_variable_set "@token", token subs.instance_variable_set "@service", service subs.instance_variable_set "@topic", topic subs.instance_variable_set "@max", max subs end |
Instance Method Details
#all(request_limit: nil) {|subscription| ... } ⇒ Enumerator
Retrieves all subscriptions by repeatedly loading #next until #next? returns ‘false`. Calls the given block once for each subscription, which is passed as the parameter.
An Enumerator is returned if no block is given.
This method may make several API calls until all subscriptions are retrieved. Be sure to use as narrow a search criteria as possible. Please use with caution.
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/gcloud/pubsub/subscription/list.rb', line 137 def all request_limit: nil request_limit = request_limit.to_i if request_limit unless block_given? return enum_for(:all, request_limit: request_limit) end results = self loop do results.each { |r| yield r } if request_limit request_limit -= 1 break if request_limit < 0 end break unless results.next? results = results.next end end |
#next ⇒ Subscription::List
Retrieve the next page of subscriptions.
76 77 78 79 80 81 82 83 84 |
# File 'lib/gcloud/pubsub/subscription/list.rb', line 76 def next return nil unless next? ensure_service! if @topic next_topic_subscriptions else next_subscriptions end end |
#next? ⇒ Boolean
Whether there a next page of subscriptions.
56 57 58 |
# File 'lib/gcloud/pubsub/subscription/list.rb', line 56 def next? !token.nil? end |