Class: TrackRelay::EventDefinition::ParamSchema
- Inherits:
-
Data
- Object
- Data
- TrackRelay::EventDefinition::ParamSchema
- 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
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#in ⇒ Object
readonly
Returns the value of attribute in.
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#required ⇒ Object
readonly
Returns the value of attribute required.
-
#sanitize ⇒ Object
readonly
Returns the value of attribute sanitize.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(name:, type:, required: false, max: nil, in: nil, format: nil, sanitize: nil) ⇒ ParamSchema
constructor
Override
initializeto default the optional slots so callers only need to passname:andtype:.
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
#format ⇒ Object (readonly)
Returns the value of attribute format
45 46 47 |
# File 'lib/track_relay/event_definition.rb', line 45 def format @format end |
#in ⇒ Object (readonly)
Returns the value of attribute in
45 46 47 |
# File 'lib/track_relay/event_definition.rb', line 45 def in @in end |
#max ⇒ Object (readonly)
Returns the value of attribute max
45 46 47 |
# File 'lib/track_relay/event_definition.rb', line 45 def max @max end |
#name ⇒ Object (readonly)
Returns the value of attribute name
45 46 47 |
# File 'lib/track_relay/event_definition.rb', line 45 def name @name end |
#required ⇒ Object (readonly)
Returns the value of attribute required
45 46 47 |
# File 'lib/track_relay/event_definition.rb', line 45 def required @required end |
#sanitize ⇒ Object (readonly)
Returns the value of attribute sanitize
45 46 47 |
# File 'lib/track_relay/event_definition.rb', line 45 def sanitize @sanitize end |
#type ⇒ Object (readonly)
Returns the value of attribute type
45 46 47 |
# File 'lib/track_relay/event_definition.rb', line 45 def type @type end |