Class: TypedEAV::Field::LongText

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

Overview

Long-text-typed field stored in the ‘text_value` column. Kept as a direct child of `Field::Base` (per ADR-0004 — array types, LongText, File, Image, Reference all stay direct children; only Text/Email/Url moved into the new `Field::ValidatedString` family). Inlines its own min_length / max_length check rather than joining the ValidatedString family because LongText does NOT carry the `:pattern` option, the `max_gte_min_length` guard, or the `validate_pattern_syntax` guard — the family base would attach validation surface LongText doesn’t want.

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!, #clear_option_cache!, #default_value, #default_value=, 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

#cast(raw) ⇒ Object



19
20
21
# File 'app/models/typed_eav/field/long_text.rb', line 19

def cast(raw)
  [raw&.to_s, false]
end

#validate_typed_value(record, val) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'app/models/typed_eav/field/long_text.rb', line 23

def validate_typed_value(record, val)
  opts = options_hash
  str = val.to_s
  if opts[:min_length] && str.length < opts[:min_length].to_i
    record.errors.add(:value, :too_short, count: opts[:min_length])
  end
  return unless opts[:max_length] && str.length > opts[:max_length].to_i

  record.errors.add(:value, :too_long, count: opts[:max_length])
end