Class: Trabox::Publisher::Google::Cloud::PubSub::OrderingKey

Inherits:
Object
  • Object
show all
Defined in:
lib/trabox/publisher/google/cloud_pubsub.rb

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ OrderingKey

Returns a new instance of OrderingKey.

Parameters:

  • key (Proc(ActiveRecord), String)


15
16
17
18
19
20
21
22
23
# File 'lib/trabox/publisher/google/cloud_pubsub.rb', line 15

def initialize(key)
  @key = if key.is_a?(Proc)
           key
         elsif key.instance_of?(String)
           ->(*) { key }
         else
           raise ArgumentError, 'OrderingKey.new should be set to Proc or String.'
         end
end

Instance Method Details

#call(*args) ⇒ String

Returns:

  • (String)


26
27
28
29
30
31
32
# File 'lib/trabox/publisher/google/cloud_pubsub.rb', line 26

def call(*args)
  key = @key.call(*args)

  raise 'OrderingKey#call should be returned String type.' unless key.instance_of?(String)

  key
end