google-cloud-pubsub 0.29.0 → 0.30.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e7f83c2402c87e054a0d08e734c8a7bbfd103d11a86a1d1feb0df5634ac09d7d
4
- data.tar.gz: 7ea51a0d33514c2feebb6eb15423ccbb5f4a65e446f4b070380eb5298dbbeaca
3
+ metadata.gz: 7b647f7265e16e47a38c39b2171f2f21823604e384830cd209b2e85b0284a5db
4
+ data.tar.gz: 62cbd134e8699a48759114fe1437286230b485b7b8598c1ee32823cb66215b80
5
5
  SHA512:
6
- metadata.gz: 379e48558ef31382d9b648cfeaf09de5ff388d3759cab4133c92cc68ceb0494cc2d742ba91495b78726581b4558b7e96842c5fa98426059a2d94865d39e84726
7
- data.tar.gz: 9b9eb864b182ff0e4435e824f3e7f75495e56e54af64880394d2b07307d898f80cfc8adc36588d132e2c55d5bd823775f895ef1c10b70e13efbf9db30a1acd72
6
+ metadata.gz: e39a2f11dbdace3f1088e3bbc0f4b883a939d0c9d7d0ff8e8978397bfe4fff20f5d162b736df7ed435f03396eb773c817970c55fdf5f414eb0bf4d698749b97f
7
+ data.tar.gz: 488f6fc246f5cc7f7d108cb7096e94cae4ea8b7680fc7e9e6f062bad987a5705825eaa4456a113f37d5f60823adaefb1c5b3a74fb48e085135a3eb3a98d9ba40
@@ -20,6 +20,8 @@
20
20
 
21
21
  gem "google-cloud-core"
22
22
  require "google/cloud"
23
+ require "google/cloud/config"
24
+ require "googleauth"
23
25
 
24
26
  module Google
25
27
  module Cloud
@@ -110,3 +112,31 @@ module Google
110
112
  end
111
113
  end
112
114
  end
115
+
116
+ # Set the default pubsub configuration
117
+ Google::Cloud.configure.add_config! :pubsub do |config|
118
+ default_project = Google::Cloud::Config.deferred do
119
+ ENV["PUBSUB_PROJECT"]
120
+ end
121
+ default_creds = Google::Cloud::Config.deferred do
122
+ Google::Cloud::Config.credentials_from_env(
123
+ "PUBSUB_CREDENTIALS", "PUBSUB_CREDENTIALS_JSON",
124
+ "PUBSUB_KEYFILE", "PUBSUB_KEYFILE_JSON"
125
+ )
126
+ end
127
+ default_emulator = Google::Cloud::Config.deferred do
128
+ ENV["PUBSUB_EMULATOR_HOST"]
129
+ end
130
+
131
+ config.add_field! :project_id, default_project, match: String, allow_nil: true
132
+ config.add_alias! :project, :project_id
133
+ config.add_field! :credentials, default_creds,
134
+ match: [String, Hash, Google::Auth::Credentials],
135
+ allow_nil: true
136
+ config.add_alias! :keyfile, :credentials
137
+ config.add_field! :scope, nil, match: [String, Array]
138
+ config.add_field! :timeout, nil, match: Integer
139
+ config.add_field! :client_config, nil, match: Hash
140
+ config.add_field! :emulator_host, default_emulator,
141
+ match: String, allow_nil: true
142
+ end
@@ -15,6 +15,8 @@
15
15
 
16
16
  require "google-cloud-pubsub"
17
17
  require "google/cloud/pubsub/project"
18
+ require "google/cloud/config"
19
+ require "google/cloud/env"
18
20
 
19
21
  module Google
20
22
  module Cloud
@@ -28,11 +30,14 @@ module Google
28
30
  # Cloud Pub/Sub allows developers to communicate between independently
29
31
  # written applications.
30
32
  #
31
- # The goal of google-cloud is to provide a API that is comfortable to
32
- # Rubyists. Authentication is handled by {Google::Cloud#pubsub}. You can
33
- # provide the project and credential information to connect to the Pub/Sub
34
- # service, or if you are running on Google Compute Engine this configuration
35
- # is taken care of for you.
33
+ # The goal of google-cloud is to provide an API that is comfortable to
34
+ # Rubyists. Your authentication credentials are detected automatically in
35
+ # Google Cloud Platform environments such as Google Compute Engine, Google
36
+ # App Engine and Google Kubernetes Engine. In other environments you can
37
+ # configure authentication easily, either directly in your code or via
38
+ # environment variables. Read more about the options for connecting in the
39
+ # [Authentication
40
+ # Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
36
41
  #
37
42
  # ```ruby
38
43
  # require "google/cloud/pubsub"
@@ -507,7 +512,7 @@ module Google
507
512
  # @param [Hash] client_config A hash of values to override the default
508
513
  # behavior of the API client. Optional.
509
514
  # @param [String] emulator_host Pub/Sub emulator host. Optional.
510
- # If the param is nil, ENV["PUBSUB_EMULATOR_HOST"] will be used.
515
+ # If the param is nil, uses the value of the `emulator_host` config.
511
516
  # @param [String] project Alias for the `project_id` argument. Deprecated.
512
517
  # @param [String] keyfile Alias for the `credentials` argument.
513
518
  # Deprecated.
@@ -525,19 +530,24 @@ module Google
525
530
  def self.new project_id: nil, credentials: nil, scope: nil, timeout: nil,
526
531
  client_config: nil, emulator_host: nil, project: nil,
527
532
  keyfile: nil
528
- project_id ||= (project || Pubsub::Project.default_project_id)
533
+ project_id ||= (project || default_project_id)
529
534
  project_id = project_id.to_s # Always cast to a string
530
- fail ArgumentError, "project_id is missing" if project_id.empty?
535
+ raise ArgumentError, "project_id is missing" if project_id.empty?
531
536
 
532
- emulator_host ||= ENV["PUBSUB_EMULATOR_HOST"]
537
+ scope ||= configure.scope
538
+ timeout ||= configure.timeout
539
+ client_config ||= configure.client_config
540
+ emulator_host ||= configure.emulator_host
533
541
  if emulator_host
534
542
  return Pubsub::Project.new(
535
543
  Pubsub::Service.new(
536
544
  project_id, :this_channel_is_insecure,
537
- host: emulator_host))
545
+ host: emulator_host
546
+ )
547
+ )
538
548
  end
539
549
 
540
- credentials ||= (keyfile || Pubsub::Credentials.default(scope: scope))
550
+ credentials ||= (keyfile || default_credentials(scope: scope))
541
551
  unless credentials.is_a? Google::Auth::Credentials
542
552
  credentials = Pubsub::Credentials.new credentials, scope: scope
543
553
  end
@@ -545,7 +555,55 @@ module Google
545
555
  Pubsub::Project.new(
546
556
  Pubsub::Service.new(
547
557
  project_id, credentials, timeout: timeout,
548
- client_config: client_config))
558
+ client_config: client_config
559
+ )
560
+ )
561
+ end
562
+
563
+ ##
564
+ # Configure the Google Cloud Pubsub library.
565
+ #
566
+ # The following Pubsub configuration parameters are supported:
567
+ #
568
+ # * `project_id` - (String) Identifier for a Pubsub project. (The
569
+ # parameter `project` is considered deprecated, but may also be used.)
570
+ # * `credentials` - (String, Hash, Google::Auth::Credentials) The path to
571
+ # the keyfile as a String, the contents of the keyfile as a Hash, or a
572
+ # Google::Auth::Credentials object. (See {Pubsub::Credentials}) (The
573
+ # parameter `keyfile` is considered deprecated, but may also be used.)
574
+ # * `scope` - (String, Array<String>) The OAuth 2.0 scopes controlling
575
+ # the set of resources and operations that the connection can access.
576
+ # * `retries` - (Integer) Number of times to retry requests on server
577
+ # error.
578
+ # * `timeout` - (Integer) Default timeout to use in requests.
579
+ # * `client_config` - (Hash) A hash of values to override the default
580
+ # behavior of the API client.
581
+ # * `emulator_host` - (String) Host name of the emulator. Defaults to
582
+ # `ENV["PUBSUB_EMULATOR_HOST"]`
583
+ #
584
+ # @return [Google::Cloud::Config] The configuration object the
585
+ # Google::Cloud::Pubsub library uses.
586
+ #
587
+ def self.configure
588
+ yield Google::Cloud.configure.pubsub if block_given?
589
+
590
+ Google::Cloud.configure.pubsub
591
+ end
592
+
593
+ ##
594
+ # @private Default project.
595
+ def self.default_project_id
596
+ Google::Cloud.configure.pubsub.project_id ||
597
+ Google::Cloud.configure.project_id ||
598
+ Google::Cloud.env.project_id
599
+ end
600
+
601
+ ##
602
+ # @private Default credentials.
603
+ def self.default_credentials scope: nil
604
+ Google::Cloud.configure.pubsub.credentials ||
605
+ Google::Cloud.configure.credentials ||
606
+ Pubsub::Credentials.default(scope: scope)
549
607
  end
550
608
  end
551
609
  end
@@ -93,7 +93,7 @@ module Google
93
93
  msg = create_pubsub_message data, attributes
94
94
 
95
95
  synchronize do
96
- fail "Can't publish when stopped." if @stopped
96
+ raise "Can't publish when stopped." if @stopped
97
97
 
98
98
  if @batch.nil?
99
99
  @batch ||= Batch.new self
@@ -238,7 +238,7 @@ module Google
238
238
  publish_result = PublishResult.from_grpc(item.msg)
239
239
  execute_callback_async item.callback, publish_result
240
240
  end
241
- rescue => e
241
+ rescue StandardError => e
242
242
  batch.items.each do |item|
243
243
  next unless item.callback
244
244
 
@@ -50,7 +50,7 @@ module Google
50
50
  def duration_to_number duration
51
51
  return nil if duration.nil?
52
52
 
53
- return duration.seconds if duration.nanos == 0
53
+ return duration.seconds if duration.nanos.zero?
54
54
 
55
55
  duration.seconds + (duration.nanos / 1000000000.0)
56
56
  end
@@ -38,19 +38,19 @@ module Google
38
38
  # pubsub.project_id #=> "my-project"
39
39
  #
40
40
  class Credentials < Google::Auth::Credentials
41
- SCOPE = ["https://www.googleapis.com/auth/pubsub"]
42
- PATH_ENV_VARS = %w(PUBSUB_CREDENTIALS
41
+ SCOPE = ["https://www.googleapis.com/auth/pubsub"].freeze
42
+ PATH_ENV_VARS = %w[PUBSUB_CREDENTIALS
43
43
  PUBSUB_KEYFILE
44
44
  GOOGLE_CLOUD_CREDENTIALS
45
45
  GOOGLE_CLOUD_KEYFILE
46
- GCLOUD_KEYFILE)
47
- JSON_ENV_VARS = %w(PUBSUB_CREDENTIALS_JSON
46
+ GCLOUD_KEYFILE].freeze
47
+ JSON_ENV_VARS = %w[PUBSUB_CREDENTIALS_JSON
48
48
  PUBSUB_KEYFILE_JSON
49
49
  GOOGLE_CLOUD_CREDENTIALS_JSON
50
50
  GOOGLE_CLOUD_KEYFILE_JSON
51
- GCLOUD_KEYFILE_JSON)
51
+ GCLOUD_KEYFILE_JSON].freeze
52
52
  DEFAULT_PATHS = \
53
- ["~/.config/gcloud/application_default_credentials.json"]
53
+ ["~/.config/gcloud/application_default_credentials.json"].freeze
54
54
  end
55
55
  end
56
56
  end
@@ -66,7 +66,8 @@ module Google
66
66
 
67
67
  @grpc = Google::Pubsub::V1::PubsubMessage.new(
68
68
  data: String(data).encode("ASCII-8BIT"),
69
- attributes: attributes)
69
+ attributes: attributes
70
+ )
70
71
  end
71
72
 
72
73
  ##
@@ -90,14 +91,14 @@ module Google
90
91
  def message_id
91
92
  @grpc.message_id
92
93
  end
93
- alias_method :msg_id, :message_id
94
+ alias msg_id message_id
94
95
 
95
96
  ##
96
97
  # The time at which the message was published.
97
98
  def published_at
98
99
  Convert.timestamp_to_time @grpc.publish_time
99
100
  end
100
- alias_method :publish_time, :published_at
101
+ alias publish_time published_at
101
102
 
102
103
  ##
103
104
  # @private New Message from a Google::Pubsub::V1::PubsubMessage object.
@@ -14,7 +14,6 @@
14
14
 
15
15
 
16
16
  require "google/cloud/errors"
17
- require "google/cloud/env"
18
17
  require "google/cloud/pubsub/service"
19
18
  require "google/cloud/pubsub/credentials"
20
19
  require "google/cloud/pubsub/topic"
@@ -71,16 +70,7 @@ module Google
71
70
  def project_id
72
71
  service.project
73
72
  end
74
- alias_method :project, :project_id
75
-
76
- ##
77
- # @private Default project.
78
- def self.default_project_id
79
- ENV["PUBSUB_PROJECT"] ||
80
- ENV["GOOGLE_CLOUD_PROJECT"] ||
81
- ENV["GCLOUD_PROJECT"] ||
82
- Google::Cloud.env.project_id
83
- end
73
+ alias project project_id
84
74
 
85
75
  ##
86
76
  # Retrieves topic by name.
@@ -166,8 +156,8 @@ module Google
166
156
  rescue Google::Cloud::NotFoundError
167
157
  nil
168
158
  end
169
- alias_method :get_topic, :topic
170
- alias_method :find_topic, :topic
159
+ alias get_topic topic
160
+ alias find_topic topic
171
161
 
172
162
  ##
173
163
  # Creates a new topic.
@@ -206,7 +196,7 @@ module Google
206
196
  grpc = service.create_topic topic_name
207
197
  Topic.from_grpc grpc, service, async: async
208
198
  end
209
- alias_method :new_topic, :create_topic
199
+ alias new_topic create_topic
210
200
 
211
201
  ##
212
202
  # Retrieves a list of topics for the given project.
@@ -245,8 +235,8 @@ module Google
245
235
  grpc = service.list_topics options
246
236
  Topic::List.from_grpc grpc, service, max
247
237
  end
248
- alias_method :find_topics, :topics
249
- alias_method :list_topics, :topics
238
+ alias find_topics topics
239
+ alias list_topics topics
250
240
 
251
241
  ##
252
242
  # Retrieves subscription by name.
@@ -291,8 +281,8 @@ module Google
291
281
  rescue Google::Cloud::NotFoundError
292
282
  nil
293
283
  end
294
- alias_method :get_subscription, :subscription
295
- alias_method :find_subscription, :subscription
284
+ alias get_subscription subscription
285
+ alias find_subscription subscription
296
286
 
297
287
  ##
298
288
  # Retrieves a list of subscriptions for the given project.
@@ -330,8 +320,8 @@ module Google
330
320
  grpc = service.list_subscriptions options
331
321
  Subscription::List.from_grpc grpc, service, max
332
322
  end
333
- alias_method :find_subscriptions, :subscriptions
334
- alias_method :list_subscriptions, :subscriptions
323
+ alias find_subscriptions subscriptions
324
+ alias list_subscriptions subscriptions
335
325
 
336
326
 
337
327
  ##
@@ -370,8 +360,8 @@ module Google
370
360
  grpc = service.list_snapshots options
371
361
  Snapshot::List.from_grpc grpc, service, max
372
362
  end
373
- alias_method :find_snapshots, :snapshots
374
- alias_method :list_snapshots, :snapshots
363
+ alias find_snapshots snapshots
364
+ alias list_snapshots snapshots
375
365
 
376
366
  protected
377
367
 
@@ -379,7 +369,7 @@ module Google
379
369
  # @private Raise an error unless an active connection to the service is
380
370
  # available.
381
371
  def ensure_service!
382
- fail "Must have active connection to service" unless service
372
+ raise "Must have active connection to service" unless service
383
373
  end
384
374
 
385
375
  ##
@@ -32,7 +32,7 @@ module Google
32
32
  def message
33
33
  @message
34
34
  end
35
- alias_method :msg, :message
35
+ alias msg message
36
36
 
37
37
  ##
38
38
  # The message's data.
@@ -52,14 +52,14 @@ module Google
52
52
  def message_id
53
53
  message.message_id
54
54
  end
55
- alias_method :msg_id, :message_id
55
+ alias msg_id message_id
56
56
 
57
57
  ##
58
58
  # The time at which the message was published.
59
59
  def published_at
60
60
  message.published_at
61
61
  end
62
- alias_method :publish_time, :published_at
62
+ alias publish_time published_at
63
63
 
64
64
  ##
65
65
  # The error that was raised when published, if any.
@@ -68,7 +68,7 @@ module Google
68
68
  def message
69
69
  Message.from_grpc @grpc.message
70
70
  end
71
- alias_method :msg, :message
71
+ alias msg message
72
72
 
73
73
  ##
74
74
  # The received message payload. This data is a list of bytes encoded as
@@ -89,14 +89,14 @@ module Google
89
89
  def message_id
90
90
  message.message_id
91
91
  end
92
- alias_method :msg_id, :message_id
92
+ alias msg_id message_id
93
93
 
94
94
  ##
95
95
  # The time at which the message was published.
96
96
  def published_at
97
97
  message.published_at
98
98
  end
99
- alias_method :publish_time, :published_at
99
+ alias publish_time published_at
100
100
 
101
101
  ##
102
102
  # Acknowledges receipt of the message.
@@ -123,7 +123,7 @@ module Google
123
123
  ensure_subscription!
124
124
  subscription.acknowledge ack_id
125
125
  end
126
- alias_method :ack!, :acknowledge!
126
+ alias ack! acknowledge!
127
127
 
128
128
  ##
129
129
  # Modifies the acknowledge deadline for the message.
@@ -160,7 +160,7 @@ module Google
160
160
  ensure_subscription!
161
161
  subscription.delay new_deadline, ack_id
162
162
  end
163
- alias_method :modify_ack_deadline!, :delay!
163
+ alias modify_ack_deadline! delay!
164
164
 
165
165
  ##
166
166
  # Resets the acknowledge deadline for the message without acknowledging
@@ -190,8 +190,8 @@ module Google
190
190
  def reject!
191
191
  delay! 0
192
192
  end
193
- alias_method :nack!, :reject!
194
- alias_method :ignore!, :reject!
193
+ alias nack! reject!
194
+ alias ignore! reject!
195
195
 
196
196
  ##
197
197
  # @private New ReceivedMessage from a
@@ -208,7 +208,7 @@ module Google
208
208
  ##
209
209
  # Raise an error unless an active subscription is available.
210
210
  def ensure_subscription!
211
- fail "Must have active subscription" unless subscription
211
+ raise "Must have active subscription" unless subscription
212
212
  end
213
213
  end
214
214
  end
@@ -66,7 +66,8 @@ module Google
66
66
  timeout: timeout,
67
67
  client_config: client_config,
68
68
  lib_name: "gccl",
69
- lib_version: Google::Cloud::Pubsub::VERSION)
69
+ lib_version: Google::Cloud::Pubsub::VERSION
70
+ )
70
71
  end
71
72
  end
72
73
  attr_accessor :mocked_subscriber
@@ -78,7 +79,8 @@ module Google
78
79
  credentials: channel,
79
80
  timeout: timeout,
80
81
  lib_name: "gccl",
81
- lib_version: Google::Cloud::Pubsub::VERSION)
82
+ lib_version: Google::Cloud::Pubsub::VERSION
83
+ )
82
84
  end
83
85
  end
84
86
  attr_accessor :mocked_publisher
@@ -157,7 +157,7 @@ module Google
157
157
  # @private Raise an error unless an active connection to the service is
158
158
  # available.
159
159
  def ensure_service!
160
- fail "Must have active connection to service" unless service
160
+ raise "Must have active connection to service" unless service
161
161
  end
162
162
  end
163
163
  end
@@ -163,7 +163,7 @@ module Google
163
163
  # @private Raise an error unless an active connection to the service
164
164
  # is available.
165
165
  def ensure_service!
166
- fail "Must have active connection to service" unless @service
166
+ raise "Must have active connection to service" unless @service
167
167
  end
168
168
 
169
169
  def next_snapshots
@@ -87,7 +87,7 @@ module Google
87
87
  @started = nil
88
88
  @stopped = nil
89
89
 
90
- stream_pool = @streams.times.map do
90
+ stream_pool = Array.new(@streams) do
91
91
  Thread.new { Stream.new self }
92
92
  end
93
93
  @stream_pool = stream_pool.map(&:value)
@@ -172,7 +172,8 @@ module Google
172
172
  ##
173
173
  # @private
174
174
  def to_s
175
- format "(subscription: %s, streams: %i)", subscription_name, streams
175
+ format "(subscription: %<sub>s, streams: %<count>i)",
176
+ sub: subscription_name, count: streams
176
177
  end
177
178
 
178
179
  ##
@@ -70,10 +70,12 @@ module Google
70
70
  synchronize do
71
71
  break if @stopped
72
72
 
73
- @inventory.stop
74
73
  @stopped = true
75
- # Kill the thread since it may be sleeping
76
- @background_thread.kill if @background_thread
74
+
75
+ @inventory.stop
76
+
77
+ # signal to the background thread that we are unpaused
78
+ @pause_cond.broadcast
77
79
  end
78
80
 
79
81
  self
@@ -175,7 +177,8 @@ module Google
175
177
 
176
178
  # @private
177
179
  def to_s
178
- format "(inventory: %i, status: %s)", inventory.count, status
180
+ format "(inventory: %<inv>i, status: %<sts>s)",
181
+ inv: inventory.count, sts: status
179
182
  end
180
183
 
181
184
  # @private
@@ -188,14 +191,17 @@ module Google
188
191
  # rubocop:disable all
189
192
 
190
193
  def background_run enum
191
- until synchronize { @stopped }
194
+ loop do
192
195
  synchronize do
193
- if @paused
196
+ if @paused && !@stopped
194
197
  @pause_cond.wait
195
198
  next
196
199
  end
197
200
  end
198
201
 
202
+ # Break loop, close thread if stopped
203
+ break if synchronize { @stopped }
204
+
199
205
  begin
200
206
  # Cannot syncronize the enumerator, causes deadlock
201
207
  response = enum.next
@@ -232,8 +238,8 @@ module Google
232
238
  # Also stealthly restart the stream on Unavailable, Cancelled,
233
239
  # ResourceExhausted, and Internal.
234
240
  synchronize { start_streaming! }
235
- rescue => e
236
- fail Google::Cloud::Error.from_error(e)
241
+ rescue StandardError => e
242
+ raise Google::Cloud::Error.from_error(e)
237
243
  end
238
244
 
239
245
  # rubocop:enable all
@@ -245,6 +251,9 @@ module Google
245
251
  end
246
252
 
247
253
  def start_streaming!
254
+ # Don't allow a stream to restart if already stopped
255
+ return if @stopped
256
+
248
257
  # signal to the previous queue to shut down
249
258
  old_queue = []
250
259
  old_queue = @request_queue.dump_queue if @request_queue
@@ -270,6 +279,7 @@ module Google
270
279
  end
271
280
 
272
281
  def pause_streaming?
282
+ return if @stopped
273
283
  return if @paused
274
284
 
275
285
  @inventory.full?
@@ -284,9 +294,10 @@ module Google
284
294
  end
285
295
 
286
296
  def unpause_streaming?
297
+ return if @stopped
287
298
  return if @paused.nil?
288
299
 
289
- @inventory.count < @inventory.limit*0.8
300
+ @inventory.count < @inventory.limit * 0.8
290
301
  end
291
302
 
292
303
  def initial_input_request
@@ -341,7 +352,9 @@ module Google
341
352
  ack_ids = Array(ack_ids).flatten
342
353
  synchronize do
343
354
  @_ack_ids += ack_ids
344
- @background_thread ||= Thread.new { background_run }
355
+ unless @stopped
356
+ @background_thread ||= Thread.new { background_run }
357
+ end
345
358
  end
346
359
  end
347
360
 
@@ -103,7 +103,6 @@ module Google
103
103
  @grpc = service.update_subscription update_grpc,
104
104
  :ack_deadline_seconds
105
105
  @lazy = nil
106
- self
107
106
  end
108
107
 
109
108
  ##
@@ -126,7 +125,6 @@ module Google
126
125
  @grpc = service.update_subscription update_grpc,
127
126
  :retain_acked_messages
128
127
  @lazy = nil
129
- self
130
128
  end
131
129
 
132
130
  ##
@@ -152,7 +150,6 @@ module Google
152
150
  @grpc = service.update_subscription update_grpc,
153
151
  :message_retention_duration
154
152
  @lazy = nil
155
- self
156
153
  end
157
154
 
158
155
  ##
@@ -168,10 +165,13 @@ module Google
168
165
  def endpoint= new_endpoint
169
166
  ensure_service!
170
167
  service.modify_push_config name, new_endpoint, {}
168
+
169
+ return unless @grpc
170
+
171
171
  @grpc.push_config = Google::Pubsub::V1::PushConfig.new(
172
172
  push_endpoint: new_endpoint,
173
173
  attributes: {}
174
- ) if @grpc
174
+ )
175
175
  end
176
176
 
177
177
  ##
@@ -429,7 +429,7 @@ module Google
429
429
  service.acknowledge name, *ack_ids
430
430
  true
431
431
  end
432
- alias_method :ack, :acknowledge
432
+ alias ack acknowledge
433
433
 
434
434
  ##
435
435
  # Modifies the acknowledge deadline for messages.
@@ -463,7 +463,7 @@ module Google
463
463
  service.modify_ack_deadline name, ack_ids, new_deadline
464
464
  true
465
465
  end
466
- alias_method :modify_ack_deadline, :delay
466
+ alias modify_ack_deadline delay
467
467
 
468
468
  ##
469
469
  # Creates a new {Snapshot} from the subscription. The created snapshot
@@ -510,7 +510,7 @@ module Google
510
510
  grpc = service.create_snapshot name, snapshot_name
511
511
  Snapshot.from_grpc grpc, service
512
512
  end
513
- alias_method :new_snapshot, :create_snapshot
513
+ alias new_snapshot create_snapshot
514
514
 
515
515
  ##
516
516
  # Resets the subscription's backlog to a given {Snapshot} or to a point
@@ -604,7 +604,7 @@ module Google
604
604
  policy = Policy.from_grpc grpc
605
605
  return policy unless block_given?
606
606
  yield policy
607
- self.policy = policy
607
+ update_policy policy
608
608
  end
609
609
 
610
610
  ##
@@ -634,13 +634,14 @@ module Google
634
634
  #
635
635
  # policy.add "roles/owner", "user:owner@example.com"
636
636
  #
637
- # sub.policy = policy # API call
637
+ # sub.update_policy policy # API call
638
638
  #
639
- def policy= new_policy
639
+ def update_policy new_policy
640
640
  ensure_service!
641
641
  grpc = service.set_subscription_policy name, new_policy.to_grpc
642
642
  Policy.from_grpc grpc
643
643
  end
644
+ alias policy= update_policy
644
645
 
645
646
  ##
646
647
  # Tests the specified permissions against the [Cloud
@@ -707,7 +708,7 @@ module Google
707
708
  # @private Raise an error unless an active connection to the service is
708
709
  # available.
709
710
  def ensure_service!
710
- fail "Must have active connection to service" unless service
711
+ raise "Must have active connection to service" unless service
711
712
  end
712
713
 
713
714
  ##
@@ -184,7 +184,7 @@ module Google
184
184
  # @private Raise an error unless an active connection to the service
185
185
  # is available.
186
186
  def ensure_service!
187
- fail "Must have active connection to service" unless @service
187
+ raise "Must have active connection to service" unless @service
188
188
  end
189
189
 
190
190
  def next_subscriptions
@@ -161,8 +161,8 @@ module Google
161
161
  grpc = service.create_subscription name, subscription_name, options
162
162
  Subscription.from_grpc grpc, service
163
163
  end
164
- alias_method :create_subscription, :subscribe
165
- alias_method :new_subscription, :subscribe
164
+ alias create_subscription subscribe
165
+ alias new_subscription subscribe
166
166
 
167
167
  ##
168
168
  # Retrieves subscription by name.
@@ -205,8 +205,8 @@ module Google
205
205
  rescue Google::Cloud::NotFoundError
206
206
  nil
207
207
  end
208
- alias_method :get_subscription, :subscription
209
- alias_method :find_subscription, :subscription
208
+ alias get_subscription subscription
209
+ alias find_subscription subscription
210
210
 
211
211
  ##
212
212
  # Retrieves a list of subscription names for the given project.
@@ -246,8 +246,8 @@ module Google
246
246
  grpc = service.list_topics_subscriptions name, options
247
247
  Subscription::List.from_topic_grpc grpc, service, name, max
248
248
  end
249
- alias_method :find_subscriptions, :subscriptions
250
- alias_method :list_subscriptions, :subscriptions
249
+ alias find_subscriptions subscriptions
250
+ alias list_subscriptions subscriptions
251
251
 
252
252
  ##
253
253
  # Publishes one or more messages to the topic.
@@ -412,7 +412,7 @@ module Google
412
412
  policy = Policy.from_grpc grpc
413
413
  return policy unless block_given?
414
414
  yield policy
415
- self.policy = policy
415
+ update_policy policy
416
416
  end
417
417
 
418
418
  ##
@@ -442,13 +442,14 @@ module Google
442
442
  #
443
443
  # policy.add "roles/owner", "user:owner@example.com"
444
444
  #
445
- # topic.policy = policy # API call
445
+ # topic.update_policy policy # API call
446
446
  #
447
- def policy= new_policy
447
+ def update_policy new_policy
448
448
  ensure_service!
449
449
  grpc = service.set_topic_policy name, new_policy.to_grpc
450
450
  @policy = Policy.from_grpc grpc
451
451
  end
452
+ alias policy= update_policy
452
453
 
453
454
  ##
454
455
  # Tests the specified permissions against the [Cloud
@@ -555,7 +556,7 @@ module Google
555
556
  # @private Raise an error unless an active connection to the service is
556
557
  # available.
557
558
  def ensure_service!
558
- fail "Must have active connection to service" unless service
559
+ raise "Must have active connection to service" unless service
559
560
  end
560
561
 
561
562
  ##
@@ -162,7 +162,7 @@ module Google
162
162
  # @private Raise an error unless an active connection to the service
163
163
  # is available.
164
164
  def ensure_service!
165
- fail "Must have active connection to service" unless @service
165
+ raise "Must have active connection to service" unless @service
166
166
  end
167
167
  end
168
168
  end
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Pubsub
19
- VERSION = "0.29.0"
19
+ VERSION = "0.30.0".freeze
20
20
  end
21
21
  end
22
22
  end
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: 0.29.0
4
+ version: 0.30.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Moore
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-12-19 00:00:00.000000000 Z
12
+ date: 2018-02-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: google-cloud-core
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '1.1'
20
+ version: '1.2'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '1.1'
27
+ version: '1.2'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: google-gax
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -141,16 +141,16 @@ dependencies:
141
141
  name: rubocop
142
142
  requirement: !ruby/object:Gem::Requirement
143
143
  requirements:
144
- - - "<="
144
+ - - "~>"
145
145
  - !ruby/object:Gem::Version
146
- version: 0.35.1
146
+ version: 0.50.0
147
147
  type: :development
148
148
  prerelease: false
149
149
  version_requirements: !ruby/object:Gem::Requirement
150
150
  requirements:
151
- - - "<="
151
+ - - "~>"
152
152
  - !ruby/object:Gem::Version
153
- version: 0.35.1
153
+ version: 0.50.0
154
154
  - !ruby/object:Gem::Dependency
155
155
  name: simplecov
156
156
  requirement: !ruby/object:Gem::Requirement
@@ -259,7 +259,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
259
259
  version: '0'
260
260
  requirements: []
261
261
  rubyforge_project:
262
- rubygems_version: 2.7.3
262
+ rubygems_version: 2.7.6
263
263
  signing_key:
264
264
  specification_version: 4
265
265
  summary: API Client library for Google Cloud Pub/Sub