Class: RubyEventStore::Record
- Inherits:
-
Data
- Object
- Data
- RubyEventStore::Record
- Defined in:
- lib/ruby_event_store/record.rb
Constant Summary collapse
- StringsRequired =
StringsRequired
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#event_id ⇒ Object
readonly
Returns the value of attribute event_id.
-
#event_type ⇒ Object
readonly
Returns the value of attribute event_type.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#valid_at ⇒ Object
readonly
Returns the value of attribute valid_at.
Instance Method Summary collapse
-
#initialize(event_id:, data:, metadata:, event_type:, timestamp:, valid_at:) ⇒ Record
constructor
A new instance of Record.
- #serialize(serializer) ⇒ Object
Constructor Details
#initialize(event_id:, data:, metadata:, event_type:, timestamp:, valid_at:) ⇒ Record
Returns a new instance of Record.
5 6 7 8 9 |
# File 'lib/ruby_event_store/record.rb', line 5 def initialize(event_id:, data:, metadata:, event_type:, timestamp:, valid_at:) raise StringsRequired unless [event_id, event_type].all? { |v| v.instance_of?(String) } @serialized_records = {} super end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data
4 5 6 |
# File 'lib/ruby_event_store/record.rb', line 4 def data @data end |
#event_id ⇒ Object (readonly)
Returns the value of attribute event_id
4 5 6 |
# File 'lib/ruby_event_store/record.rb', line 4 def event_id @event_id end |
#event_type ⇒ Object (readonly)
Returns the value of attribute event_type
4 5 6 |
# File 'lib/ruby_event_store/record.rb', line 4 def event_type @event_type end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata
4 5 6 |
# File 'lib/ruby_event_store/record.rb', line 4 def @metadata end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp
4 5 6 |
# File 'lib/ruby_event_store/record.rb', line 4 def @timestamp end |
#valid_at ⇒ Object (readonly)
Returns the value of attribute valid_at
4 5 6 |
# File 'lib/ruby_event_store/record.rb', line 4 def valid_at @valid_at end |
Instance Method Details
#serialize(serializer) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ruby_event_store/record.rb', line 11 def serialize(serializer) @serialized_records[serializer] ||= SerializedRecord.new( event_id: event_id, event_type: event_type, data: serializer.dump(data), metadata: serializer.dump(), timestamp: .iso8601(TIMESTAMP_PRECISION), valid_at: valid_at.iso8601(TIMESTAMP_PRECISION), ) end |