lib/demiurge.rb
# Queue a notification to be sent later by the engine. The
# notification must include at least type, zone, location and
# actor and may include a hash of additional data, which should be
# serializable to JSON (i.e. use only basic data types.)
#
# @param type [String] The notification type of this notification
# @param zone [String, nil] The zone name for this notification. The special "admin" zone name is used for engine-wide events
# @param location [String, nil] The location name for this notification, or nil if no location
# @param actor [String, nil] The name of the acting item for this notification, or nil if no item is acting
# @param data [Hash] Additional data about this notification; please use String keys for the Hash
# @return [void]
# @since 0.0.1
Queue a notification to be sent later by the engine. The
notification must include at least type, zone, location and
actor and may include a hash of additional data, which should be
serializable to JSON
Queue a notification to be sent later by the engine . The notification must include at least type zone location and actor and may include a hash of additional data which should be serializable to JSON
def send_notification(data = {}, type:, zone:, location:, actor:, include_context:false)
      raise "Notification type must be a String, not #{type.class}!" unless type.is_a?(String)
      raise "Location must be a String, not #{location.class}!" unless location.is_a?(String) || location.nil?
      raise "Zone must be a String, not #{zone.class}!" unless zone.is_a?(String)
      raise "Acting item must be a String or nil, not #{actor.class}!" unless actor.is_a?(String) || actor.nil?
      @state_items["admin"].state["notification_id"] += 1
      cleaned_data = {}
      cleaned_data["context"] = @execution_context if include_context
      data.each do |key, val|
        cleaned_data[key.to_s] = val
      end
      cleaned_data.merge!("type" => type, "zone" => zone, "location" => location, "actor" => actor,
        "notification_id" => @state_items["admin"].state["notification_id"])
      @queued_notifications.push(cleaned_data)
    end
def send_notification ( data = { } , type : , zone : , location : , actor : , include_context : false ) raise "Notification type must be a String, not #{type.class}!" unless type . is_a? ( String ) raise "Location must be a String, not #{location.class}!" unless location . is_a? ( String ) || location . nil? raise "Zone must be a String, not #{zone.class}!" unless zone . is_a? ( String ) raise "Acting item must be a String or nil, not #{actor.class}!" unless actor . is_a? ( String ) || actor . nil? @state_items [ "admin" ] . state [ "notification_id" ] += 1 cleaned_data = { } cleaned_data [ "context" ] = @execution_context if include_context data . each do | key , val | cleaned_data [ key . to_s ] = val end cleaned_data . merge! ( "type" => type , "zone" => zone , "location" => location , "actor" => actor , "notification_id" => @state_items [ "admin" ] . state [ "notification_id" ] ) @queued_notifications . push ( cleaned_data ) end
Queue a notification to be sent later by the engine.
Queue a notification to be sent later by the engine .
# TODO: verify somehow that this is JSON-serializable?
None
void
data
Additional data about this notification; please use String keys for the Hash
Additional data about this notification ; please use String keys for the Hash
type
The notification type of this notification
The notification type of this notification
zone
The zone name for this notification. The special "admin" zone name is used for engine-wide events
The zone name for this notification . The special " admin " zone name is used for engine - wide events
location
The location name for this notification, or nil if no location
The location name for this notification or nil if no location
actor
The name of the acting item for this notification, or nil if no item is acting
The name of the acting item for this notification or nil if no item is acting
include_context
since
None