Class: EventStoreClient::DeserializedEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/event_store_client/deserialized_event.rb

Constant Summary collapse

'$>'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ DeserializedEvent

Returns a new instance of DeserializedEvent.

Parameters:

  • opts (Hash)

    a customizable set of options



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/event_store_client/deserialized_event.rb', line 26

def initialize(args = {})
  validate(args[:data]) unless args[:skip_validation]

  @data = args.fetch(:data) { {} }
  @type = args[:type] || self.class.name
  @metadata =
    args.fetch(:metadata) { {} }.
    merge(
      'type' => @type,
      'content-type' => payload_content_type
    )
  @custom_metadata = args[:custom_metadata] || {}
  @stream_name = args[:stream_name]
  @stream_revision = args[:stream_revision]
  @prepare_position = args[:prepare_position]
  @commit_position = args[:commit_position]
  @title = args[:title]
  @id = args[:id]
end

Instance Attribute Details

#commit_positionObject (readonly)

Returns the value of attribute commit_position.



10
11
12
# File 'lib/event_store_client/deserialized_event.rb', line 10

def commit_position
  @commit_position
end

#custom_metadataObject (readonly)

Returns the value of attribute custom_metadata.



10
11
12
# File 'lib/event_store_client/deserialized_event.rb', line 10

def 
  @custom_metadata
end

#dataObject (readonly)

Returns the value of attribute data.



10
11
12
# File 'lib/event_store_client/deserialized_event.rb', line 10

def data
  @data
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/event_store_client/deserialized_event.rb', line 10

def id
  @id
end

#metadataObject (readonly)

Returns the value of attribute metadata.



10
11
12
# File 'lib/event_store_client/deserialized_event.rb', line 10

def 
  @metadata
end

#prepare_positionObject (readonly)

Returns the value of attribute prepare_position.



10
11
12
# File 'lib/event_store_client/deserialized_event.rb', line 10

def prepare_position
  @prepare_position
end

#stream_nameObject (readonly)

Returns the value of attribute stream_name.



10
11
12
# File 'lib/event_store_client/deserialized_event.rb', line 10

def stream_name
  @stream_name
end

#stream_revisionObject (readonly)

Returns the value of attribute stream_revision.



10
11
12
# File 'lib/event_store_client/deserialized_event.rb', line 10

def stream_revision
  @stream_revision
end

#titleObject (readonly)

Returns the value of attribute title.



10
11
12
# File 'lib/event_store_client/deserialized_event.rb', line 10

def title
  @title
end

#typeObject (readonly)

Returns the value of attribute type.



10
11
12
# File 'lib/event_store_client/deserialized_event.rb', line 10

def type
  @type
end

Instance Method Details

#==(other) ⇒ Boolean

Implements comparison of ‘EventStoreClient::DeserializedEvent`-s. Two events matches if all of their attributes matches

Parameters:

Returns:

  • (Boolean)


58
59
60
61
62
# File 'lib/event_store_client/deserialized_event.rb', line 58

def ==(other)
  return false unless other.is_a?(EventStoreClient::DeserializedEvent)

  meaningful_attrs(to_h) == meaningful_attrs(other.to_h)
end

#link?Boolean

Detect whether an event is a link event

Returns:

  • (Boolean)


75
76
77
# File 'lib/event_store_client/deserialized_event.rb', line 75

def link?
  type == LINK_TYPE
end

#payload_content_typeObject

content type of the event data



50
51
52
# File 'lib/event_store_client/deserialized_event.rb', line 50

def payload_content_type
  'application/json'
end

#schemaObject

event schema



47
# File 'lib/event_store_client/deserialized_event.rb', line 47

def schema; end

#system?Boolean

Detect whether an event is a system event

Returns:

  • (Boolean)


81
82
83
84
85
# File 'lib/event_store_client/deserialized_event.rb', line 81

def system?
  return false unless type

  type.start_with?('$')
end

#to_hHash

Returns:

  • (Hash)


65
66
67
68
69
70
71
# File 'lib/event_store_client/deserialized_event.rb', line 65

def to_h
  instance_variables.each_with_object({}) do |var, result|
    key = var.to_s
    key[0] = '' # remove @ sign
    result[key.to_sym] = instance_variable_get(var)
  end
end