Class: SiteMaps::Notification::Event

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/site_maps/notification/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: {})


21
22
23
24
# File 'lib/site_maps/notification/event.rb', line 21

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

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



11
12
13
# File 'lib/site_maps/notification/event.rb', line 11

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.



45
46
47
# File 'lib/site_maps/notification/event.rb', line 45

def listener_method
  @listener_method ||= Primitive::String.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



36
37
38
39
40
41
42
# File 'lib/site_maps/notification/event.rb', line 36

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