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
# 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
   =
    args.fetch(:metadata) { {} }.
    merge(
      'type' => @type,
      'content-type' => payload_content_type
    )
  @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

#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 
  
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)


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

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

  to_h == other.to_h
end

#link?Boolean

Detect whether an event is a link event

Returns:

  • (Boolean)


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

def link?
  type == LINK_TYPE
end

#payload_content_typeObject

content type of the event data



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

def payload_content_type
  'application/json'
end

#schemaObject

event schema



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

def schema; end

#to_hHash

Returns:

  • (Hash)


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

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