Class: Easyop::Events::Event
- Inherits:
-
Object
- Object
- Easyop::Events::Event
- Defined in:
- lib/easyop/events/event.rb
Overview
An immutable domain event value object.
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Instance Method Summary collapse
-
#initialize(name:, payload: {}, metadata: {}, timestamp: nil, source: nil) ⇒ Event
constructor
A new instance of Event.
- #inspect ⇒ Object
-
#to_h ⇒ Hash
Serializable hash representation.
Constructor Details
#initialize(name:, payload: {}, metadata: {}, timestamp: nil, source: nil) ⇒ Event
Returns a new instance of Event.
24 25 26 27 28 29 30 31 |
# File 'lib/easyop/events/event.rb', line 24 def initialize(name:, payload: {}, metadata: {}, timestamp: nil, source: nil) @name = name.to_s.freeze @payload = payload.freeze @metadata = .freeze @timestamp = ( || Time.now).freeze @source = source&.freeze freeze end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
17 18 19 |
# File 'lib/easyop/events/event.rb', line 17 def @metadata end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
17 18 19 |
# File 'lib/easyop/events/event.rb', line 17 def name @name end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
17 18 19 |
# File 'lib/easyop/events/event.rb', line 17 def payload @payload end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
17 18 19 |
# File 'lib/easyop/events/event.rb', line 17 def source @source end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
17 18 19 |
# File 'lib/easyop/events/event.rb', line 17 def @timestamp end |
Instance Method Details
#inspect ⇒ Object
39 40 41 |
# File 'lib/easyop/events/event.rb', line 39 def inspect "#<Easyop::Events::Event name=#{@name.inspect} source=#{@source.inspect}>" end |
#to_h ⇒ Hash
Returns serializable hash representation.
34 35 36 37 |
# File 'lib/easyop/events/event.rb', line 34 def to_h { name: @name, payload: @payload, metadata: @metadata, timestamp: @timestamp, source: @source } end |