Class: Synapse::MessageBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/synapse/common/message_builder.rb

Overview

Builder that is used to easily create and populate messages

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#idString

Returns:

  • (String)


5
6
7
# File 'lib/synapse/common/message_builder.rb', line 5

def id
  @id
end

#metadataHash

Returns:

  • (Hash)


8
9
10
# File 'lib/synapse/common/message_builder.rb', line 8

def 
  @metadata
end

#payloadObject

Returns:

  • (Object)


11
12
13
# File 'lib/synapse/common/message_builder.rb', line 11

def payload
  @payload
end

#timestampTime

Returns:

  • (Time)


14
15
16
# File 'lib/synapse/common/message_builder.rb', line 14

def timestamp
  @timestamp
end

Class Method Details

.build {|MessageBuilder| ... } ⇒ Message

Convenience method that yields a new builder, populates defaults and returns the newly built message instance

Yields:

Returns:



21
22
23
24
25
26
27
28
# File 'lib/synapse/common/message_builder.rb', line 21

def self.build
  builder = self.new

  yield builder if block_given?

  builder.populate_defaults
  builder.build
end

Instance Method Details

#buildMessage

Returns:



31
32
33
# File 'lib/synapse/common/message_builder.rb', line 31

def build
  Message.new @id, @metadata, @payload, @timestamp
end

#populate_defaultsundefined

Returns:

  • (undefined)


36
37
38
39
40
# File 'lib/synapse/common/message_builder.rb', line 36

def populate_defaults
  @id ||= IdentifierFactory.instance.generate
  @metadata ||= Hash.new
  @timestamp ||= Time.now
end