Class: TypedEAV::Field::ValidatedString

Inherits:
Base show all
Defined in:
app/models/typed_eav/field/validated_string.rb

Overview

Intermediate STI base for string-valued field families that share a min_length / max_length / pattern validation surface.

Leaves: Field::Text, Field::Email, Field::Url.

Hoists the string_value storage declaration, the store_accessor :options, :min_length, :max_length, :pattern line, the min_length / max_length numericality validators, the max_gte_min_length guard, the validate_pattern_syntax guard, and the protected validate_length / validate_pattern helpers — all previously duplicated across Text/Email/Url with one drift gap (max_gte_min_length was only on Text).

Default validate_typed_value runs validate_length plus validate_pattern if pattern.present?. Leaves override and call super to layer on their format-specific check (Email's EMAIL_FORMAT, Url's URL_FORMAT).

Public extension point: external authors can subclass this directly to inherit the full min/max/pattern surface (see README §"Custom field types"). STI dispatch is unaffected — leaves still store their own class names in the type column.

Direct Known Subclasses

Email, Text, Url

Constant Summary

Constants inherited from Base

Base::RESERVED_NAMES

Constants included from TypedStorage

TypedStorage::DEFAULT_OPERATORS_BY_COLUMN, TypedStorage::FALLBACK_OPERATORS

Instance Method Summary collapse

Methods inherited from Base

#allowed_option_values, #array_field?, #backfill_default!, #cast, #clear_option_cache!, #default_value, #default_value=, #display_name, export_schema, #field_type_name, import_schema, #insert_at, #move_higher, #move_lower, #move_to_bottom, #move_to_top, #optionable?

Methods included from TypedStorage

#after_snapshot, #apply_default, #before_snapshot, #read_value, #value_changed?, #write_value

Instance Method Details

#validate_typed_value(record, val) ⇒ Object



39
40
41
42
# File 'app/models/typed_eav/field/validated_string.rb', line 39

def validate_typed_value(record, val)
  validate_length(record, val)
  validate_pattern(record, val) if pattern.present?
end