Class: Synapse::MessageBuilder
- Inherits:
-
Object
- Object
- Synapse::MessageBuilder
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
#id ⇒ String
5
6
7
|
# File 'lib/synapse/common/message_builder.rb', line 5
def id
@id
end
|
8
9
10
|
# File 'lib/synapse/common/message_builder.rb', line 8
def metadata
@metadata
end
|
#payload ⇒ Object
11
12
13
|
# File 'lib/synapse/common/message_builder.rb', line 11
def payload
@payload
end
|
#timestamp ⇒ 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
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
31
32
33
|
# File 'lib/synapse/common/message_builder.rb', line 31
def build
Message.new @id, @metadata, @payload, @timestamp
end
|
#populate_defaults ⇒ 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
|