Class: Event

Inherits:
Struct
  • Object
show all
Defined in:
lib/http_eventstore/event.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, data, event_id = nil, id = nil, position = nil, stream_name = nil) ⇒ Event

Returns a new instance of Event.



4
5
6
7
# File 'lib/http_eventstore/event.rb', line 4

def initialize(type, data, event_id=nil, id=nil, position=nil, stream_name=nil)
  event_id = SecureRandom.uuid if event_id.nil?
  super
end

Instance Attribute Details

#dataObject

Returns the value of attribute data

Returns:

  • (Object)

    the current value of data



3
4
5
# File 'lib/http_eventstore/event.rb', line 3

def data
  @data
end

#event_idObject

Returns the value of attribute event_id

Returns:

  • (Object)

    the current value of event_id



3
4
5
# File 'lib/http_eventstore/event.rb', line 3

def event_id
  @event_id
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



3
4
5
# File 'lib/http_eventstore/event.rb', line 3

def id
  @id
end

#positionObject

Returns the value of attribute position

Returns:

  • (Object)

    the current value of position



3
4
5
# File 'lib/http_eventstore/event.rb', line 3

def position
  @position
end

#stream_nameObject

Returns the value of attribute stream_name

Returns:

  • (Object)

    the current value of stream_name



3
4
5
# File 'lib/http_eventstore/event.rb', line 3

def stream_name
  @stream_name
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



3
4
5
# File 'lib/http_eventstore/event.rb', line 3

def type
  @type
end

Instance Method Details

#to_json(options) ⇒ Object



13
14
15
# File 'lib/http_eventstore/event.rb', line 13

def to_json(options)
  self.to_h.to_json
end

#validateObject



9
10
11
# File 'lib/http_eventstore/event.rb', line 9

def validate
  [self.event_id, self.type, self.data].any? { |var| var.nil? || var.empty? }
end