Class: TrackRelay::EventDefinition::ParamSchema

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

Overview

The schema of a single param within an event definition.

‘name` is the param’s Symbol key. ‘type` is one of `:integer`, `:string`, `:float`, `:boolean`, `:datetime`. The remaining slots are optional validator hooks consumed by TrackRelay::EventPayload#validate!:

  • ‘required` (Boolean) — when true, missing values raise ValidationError.

  • ‘max` (Integer) — for strings, max length; for numbers, max value. Overflows raise (no silent truncation).

  • ‘in` (Array) — inclusion list; values not in the list raise.

  • ‘format` (Regexp) — applied to coerced strings; mismatches raise.

  • ‘sanitize` (Callable) — applied to the raw value BEFORE coercion and validation, so sanitization can preempt max/format checks.

‘Data.define` (Ruby 3.2+) gives us a frozen value object with a keyword constructor, equality by value, and zero ceremony.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, type:, required: false, max: nil, in: nil, format: nil, sanitize: nil) ⇒ ParamSchema

Override ‘initialize` to default the optional slots so callers only need to pass `name:` and `type:`.



56
57
58
# File 'lib/track_relay/event_definition.rb', line 56

def initialize(name:, type:, required: false, max: nil, in: nil, format: nil, sanitize: nil)
  super
end

Instance Attribute Details

#formatObject (readonly)

Returns the value of attribute format

Returns:

  • (Object)

    the current value of format



45
46
47
# File 'lib/track_relay/event_definition.rb', line 45

def format
  @format
end

#inObject (readonly)

Returns the value of attribute in

Returns:

  • (Object)

    the current value of in



45
46
47
# File 'lib/track_relay/event_definition.rb', line 45

def in
  @in
end

#maxObject (readonly)

Returns the value of attribute max

Returns:

  • (Object)

    the current value of max



45
46
47
# File 'lib/track_relay/event_definition.rb', line 45

def max
  @max
end

#nameObject (readonly)

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



45
46
47
# File 'lib/track_relay/event_definition.rb', line 45

def name
  @name
end

#requiredObject (readonly)

Returns the value of attribute required

Returns:

  • (Object)

    the current value of required



45
46
47
# File 'lib/track_relay/event_definition.rb', line 45

def required
  @required
end

#sanitizeObject (readonly)

Returns the value of attribute sanitize

Returns:

  • (Object)

    the current value of sanitize



45
46
47
# File 'lib/track_relay/event_definition.rb', line 45

def sanitize
  @sanitize
end

#typeObject (readonly)

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



45
46
47
# File 'lib/track_relay/event_definition.rb', line 45

def type
  @type
end