Class: Event

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Event.


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

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

Instance Attribute Details

#created_timeObject

Returns the value of attribute created_time

Returns:

  • (Object)

    the current value of created_time


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

def created_time
  @created_time
end

#dataObject

Returns the value of attribute data

Returns:

  • (Object)

    the current value of data


3
4
5
# File 'lib/http_event_store/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_event_store/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_event_store/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_event_store/event.rb', line 3

def position
  @position
end

#source_event_uriObject

Returns the value of attribute source_event_uri

Returns:

  • (Object)

    the current value of source_event_uri


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

def source_event_uri
  @source_event_uri
end

#stream_nameObject

Returns the value of attribute stream_name

Returns:

  • (Object)

    the current value of stream_name


3
4
5
# File 'lib/http_event_store/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_event_store/event.rb', line 3

def type
  @type
end

Instance Method Details

#to_json(options) ⇒ Object


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

def to_json(options)
  self.to_h.to_json
end

#validateObject


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

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