Class: Conrad::Processors::AddUUID

Inherits:
Object
  • Object
show all
Defined in:
lib/conrad/processors/add_uuid.rb

Overview

Generalized processor for inserting a UUID into the event. Allows configuring the key used for insertion.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uuid_key = :event_uuid) ⇒ AddUUID

Returns a new instance of AddUUID.

Parameters:

  • uuid_key (Symbol) (defaults to: :event_uuid)

    key to use for the generated UUID



15
16
17
# File 'lib/conrad/processors/add_uuid.rb', line 15

def initialize(uuid_key = :event_uuid)
  @uuid_key = uuid_key
end

Instance Attribute Details

#uuid_keyObject (readonly)

The key inserted into the event hash for the generated UUID.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/conrad/processors/add_uuid.rb', line 11

class AddUUID
  attr_reader :uuid_key

  # @param uuid_key [Symbol] key to use for the generated UUID
  def initialize(uuid_key = :event_uuid)
    @uuid_key = uuid_key
  end

  # @param event [Hash] the current event
  #
  # @return [Hash] the hash with the UUID inserted
  def call(event)
    event.merge(uuid_key => SecureRandom.uuid)
  end
end

Instance Method Details

#call(event) ⇒ Hash

Returns the hash with the UUID inserted.

Parameters:

  • event (Hash)

    the current event

Returns:

  • (Hash)

    the hash with the UUID inserted



22
23
24
# File 'lib/conrad/processors/add_uuid.rb', line 22

def call(event)
  event.merge(uuid_key => SecureRandom.uuid)
end