Class: RubyEventStore::SerializedRecord
- Inherits:
-
Object
- Object
- RubyEventStore::SerializedRecord
- Defined in:
- lib/ruby_event_store/serialized_record.rb
Constant Summary collapse
- StringsRequired =
Class.new(StandardError)
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
- #==(other) ⇒ Object (also: #eql?)
- #deserialize(serializer) ⇒ Object
- #hash ⇒ Object
-
#initialize(event_id:, data:, metadata:, event_type:, timestamp:, valid_at:) ⇒ SerializedRecord
constructor
A new instance of SerializedRecord.
- #to_h ⇒ Object
Constructor Details
#initialize(event_id:, data:, metadata:, event_type:, timestamp:, valid_at:) ⇒ SerializedRecord
Returns a new instance of SerializedRecord.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/ruby_event_store/serialized_record.rb', line 6 def initialize(event_id:, data:, metadata:, event_type:, timestamp:, valid_at:) raise StringsRequired unless [event_id, event_type].all? { |v| v.instance_of?(String) } @event_id = event_id @data = data @metadata = @event_type = event_type @timestamp = @valid_at = valid_at freeze end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
17 18 19 |
# File 'lib/ruby_event_store/serialized_record.rb', line 17 def data @data end |
#event_id ⇒ Object (readonly)
Returns the value of attribute event_id.
17 18 19 |
# File 'lib/ruby_event_store/serialized_record.rb', line 17 def event_id @event_id end |
#event_type ⇒ Object (readonly)
Returns the value of attribute event_type.
17 18 19 |
# File 'lib/ruby_event_store/serialized_record.rb', line 17 def event_type @event_type end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
17 18 19 |
# File 'lib/ruby_event_store/serialized_record.rb', line 17 def @metadata end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
17 18 19 |
# File 'lib/ruby_event_store/serialized_record.rb', line 17 def @timestamp end |
#valid_at ⇒ Object (readonly)
Returns the value of attribute valid_at.
17 18 19 |
# File 'lib/ruby_event_store/serialized_record.rb', line 17 def valid_at @valid_at end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
23 24 25 26 27 |
# File 'lib/ruby_event_store/serialized_record.rb', line 23 def ==(other) other.instance_of?(self.class) && other.event_id.eql?(event_id) && other.data.eql?(data) && other..eql?() && other.event_type.eql?(event_type) && other..eql?() && other.valid_at.eql?(valid_at) end |
#deserialize(serializer) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ruby_event_store/serialized_record.rb', line 40 def deserialize(serializer) Record.new( event_id: event_id, event_type: event_type, data: serializer.load(data), metadata: serializer.load(), timestamp: Time.iso8601(), valid_at: Time.iso8601(valid_at) ) end |
#hash ⇒ Object
19 20 21 |
# File 'lib/ruby_event_store/serialized_record.rb', line 19 def hash [event_id, data, , event_type, , valid_at].hash ^ self.class.hash end |
#to_h ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ruby_event_store/serialized_record.rb', line 29 def to_h { event_id: event_id, data: data, metadata: , event_type: event_type, timestamp: , valid_at: valid_at } end |