Class: TrackRelay::DSL::ParamBuilder

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

Overview

The DSL receiver for the body of ‘event :name do … end`.

Each type method (‘integer`, `string`, `float`, `boolean`, `datetime`) records a EventDefinition::ParamSchema keyed by param name. `user_property` accumulates user-property declarations separately so they can be passed through to the resulting EventDefinition without polluting `params`.

ParamBuilder does NOT validate or register anything itself — that is EventBuilder‘s job. Keeping the builder side-effect-free makes it trivial to test and lets EventBuilder run validation against the complete definition (so e.g. param-count overflow is reported with the full param set).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event_name) ⇒ ParamBuilder

Returns a new instance of ParamBuilder.

Parameters:

  • event_name (Symbol)

    the name of the surrounding event; stored for diagnostic context only



25
26
27
28
29
# File 'lib/track_relay/dsl/param_builder.rb', line 25

def initialize(event_name)
  @event_name = event_name
  @params = {}
  @user_properties = {}
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



21
22
23
# File 'lib/track_relay/dsl/param_builder.rb', line 21

def params
  @params
end

#user_propertiesObject (readonly)

Returns the value of attribute user_properties.



21
22
23
# File 'lib/track_relay/dsl/param_builder.rb', line 21

def user_properties
  @user_properties
end

Instance Method Details

#boolean(name, **opts) ⇒ Object



47
48
49
# File 'lib/track_relay/dsl/param_builder.rb', line 47

def boolean(name, **opts)
  record_param(name, :boolean, opts)
end

#datetime(name, **opts) ⇒ Object



51
52
53
# File 'lib/track_relay/dsl/param_builder.rb', line 51

def datetime(name, **opts)
  record_param(name, :datetime, opts)
end

#float(name, **opts) ⇒ Object



43
44
45
# File 'lib/track_relay/dsl/param_builder.rb', line 43

def float(name, **opts)
  record_param(name, :float, opts)
end

#integer(name, **opts) ⇒ EventDefinition::ParamSchema

Parameters:

  • name (Symbol)

    param name

  • opts (Hash)

    optional ParamSchema slots (required, max, in, format, sanitize)

Returns:



35
36
37
# File 'lib/track_relay/dsl/param_builder.rb', line 35

def integer(name, **opts)
  record_param(name, :integer, opts)
end

#string(name, **opts) ⇒ Object



39
40
41
# File 'lib/track_relay/dsl/param_builder.rb', line 39

def string(name, **opts)
  record_param(name, :string, opts)
end

#user_property(name, type) ⇒ Object

Declare a user property on the surrounding event. Accumulated separately from regular params so EventDefinition can keep them in ‘user_properties`.

Parameters:

  • name (Symbol)
  • type (Symbol)

    one of the type symbols (‘:string`, `:integer`, etc.)



62
63
64
# File 'lib/track_relay/dsl/param_builder.rb', line 62

def user_property(name, type)
  @user_properties[name] = type
end