class ROM::Notifications::Event

Event object

@api public

Attributes

id[R]

@!attribute [r] id

@return [Symbol] The event identifier

Public Class Methods

new(id, payload = EMPTY_HASH) click to toggle source

Initialize a new event

@param [Symbol] id The event identifier @param [Hash] payload Optional payload

@return [Event]

@api private

# File lib/rom/support/notifications.rb, line 94
def initialize(id, payload = EMPTY_HASH)
  @id = id
  @payload = payload
end

Public Instance Methods

[](name) click to toggle source

Get data from the payload

@param [String,Symbol] name

@api public

# File lib/rom/support/notifications.rb, line 104
def [](name)
  @payload.fetch(name)
end
payload(data = nil) click to toggle source

Get or set a payload

@overload

@return [Hash] payload

@overload payload(data)

@param [Hash] data A new payload
@return [Event] A copy of the event with the provided payload

@api public

# File lib/rom/support/notifications.rb, line 128
def payload(data = nil)
  if data
    self.class.new(id, @payload.merge(data))
  else
    @payload
  end
end
to_h() click to toggle source

Coerce an event to a hash

@return [Hash]

@api public

# File lib/rom/support/notifications.rb, line 113
def to_h
  @payload
end
Also aliased as: to_hash
to_hash()
Alias for: to_h
trigger(listener, query = EMPTY_HASH) click to toggle source

Trigger the event

@param [#call] listener @param [Hash] query

@api private

# File lib/rom/support/notifications.rb, line 142
def trigger(listener, query = EMPTY_HASH)
  listener.(self) if trigger?(query)
end
trigger?(query) click to toggle source

@api private

# File lib/rom/support/notifications.rb, line 147
def trigger?(query)
  query.empty? || query.all? { |key, value| @payload[key] == value }
end