Class: TypedEAV::Field::Date

Inherits:
RangeBounded show all
Defined in:
app/models/typed_eav/field/date.rb

Overview

Date-typed field with optional min_date/max_date guards. Declares its own ‘date_value` storage and `:min_date`/`:max_date` `store_accessor`. `validate_date_range` is inherited from `Field::RangeBounded`.

Latent-bug fix (per ADR-0004): the ‘validates :max_date, comparison: { greater_than_or_equal_to: :min_date }` macro now applies here (previously only Integer/Decimal carried it). A Date field configured with `max_date < min_date` fails at field-save instead of saving silently.

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



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

def cast(raw)
  return [nil, false] if raw.nil?

  casted = raw.is_a?(::Date) ? raw : ::Date.parse(raw.to_s)
  [casted, false]
rescue ::Date::Error
  [nil, true]
end

#validate_typed_value(record, val) ⇒ Object



34
35
36
# File 'app/models/typed_eav/field/date.rb', line 34

def validate_typed_value(record, val)
  validate_date_range(record, val)
end