Class: TrackRelay::EventDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/track_relay/event_definition.rb

Overview

Catalog metadata for a single event.

An EventDefinition is the immutable description of an event as declared in TrackRelay.catalog do ... end. It holds the event name, the schema of every declared param (a Hash of ParamSchema keyed by param name), and any user_property declarations.

EventDefinition is paired with EventPayload at runtime: the definition is the schema, the payload is the data, and payload.validate! checks the data against the schema.

Instances are deep-frozen at construction so the catalog cannot be mutated after load. Re-defining an event requires Catalog.clear!.

Examples:

schema = TrackRelay::EventDefinition::ParamSchema.new(
  name: :article_id, type: :integer, required: true
)
definition = TrackRelay::EventDefinition.new(
  name: :article_viewed,
  params: {article_id: schema}
)
definition.params[:article_id].type  # => :integer

Defined Under Namespace

Classes: ParamSchema

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, params: {}, user_properties: {}) ⇒ EventDefinition

Returns a new instance of EventDefinition.

Parameters:

  • name (Symbol)

    event name (e.g. :article_viewed)

  • params (Hash{Symbol => ParamSchema}) (defaults to: {})

    param schemas keyed by name

  • user_properties (Hash{Symbol => Symbol}) (defaults to: {})

    user-property names mapped to their type (e.g. {plan: :string})



67
68
69
70
71
72
# File 'lib/track_relay/event_definition.rb', line 67

def initialize(name:, params: {}, user_properties: {})
  @name = name
  @params = params.freeze
  @user_properties = user_properties.freeze
  freeze
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



61
62
63
# File 'lib/track_relay/event_definition.rb', line 61

def name
  @name
end

#paramsObject (readonly)

Returns the value of attribute params.



61
62
63
# File 'lib/track_relay/event_definition.rb', line 61

def params
  @params
end

#user_propertiesObject (readonly)

Returns the value of attribute user_properties.



61
62
63
# File 'lib/track_relay/event_definition.rb', line 61

def user_properties
  @user_properties
end