Class: Esse::Events::Event

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/esse/events/event.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, payload = {}) ⇒ Event

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize a new event

Parameters:

  • id (Symbol, String)

    The event identifier

  • payload (Hash) (defaults to: {})


20
21
22
23
# File 'lib/esse/events/event.rb', line 20

def initialize(id, payload = {})
  @id = id
  @payload = payload
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/esse/events/event.rb', line 10

def id
  @id
end

Instance Method Details

#listener_methodObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



44
45
46
# File 'lib/esse/events/event.rb', line 44

def listener_method
  @listener_method ||= Hstring.new("on_#{id}").underscore.to_sym
end

#Hash #payload(data) ⇒ Event

Get or set a payload

Overloads:

  • #Hash

    Returns payload.

    Returns:

    • (Hash)

      payload

  • #payload(data) ⇒ Event

    Returns A copy of the event with the provided payload.

    Parameters:

    • data (Hash)

      A new payload

    Returns:

    • (Event)

      A copy of the event with the provided payload



35
36
37
38
39
40
41
# File 'lib/esse/events/event.rb', line 35

def payload(data = nil)
  if data
    self.class.new(id, @payload.merge(data))
  else
    @payload
  end
end