Class: TypedEAV::Field::DateArray

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

Constant Summary

Constants inherited from Base

Base::RESERVED_NAMES

Constants included from ColumnMapping

ColumnMapping::DEFAULT_OPERATORS_BY_COLUMN, ColumnMapping::FALLBACK_OPERATORS

Instance Method Summary collapse

Methods inherited from Base

#allowed_option_values, #clear_option_cache!, #default_value, #default_value=, #field_type_name, #optionable?

Instance Method Details

#array_field?Boolean

Returns:



11
# File 'app/models/typed_eav/field/date_array.rb', line 11

def array_field? = true

#cast(raw) ⇒ Object

See IntegerArray#cast for the “invalid element → whole value invalid” rationale.



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/models/typed_eav/field/date_array.rb', line 15

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

  elements = Array(raw).reject { |v| v.nil? || (v.respond_to?(:empty?) && v.empty?) }
  casted = elements.map do |v|
    ::Date.parse(v.to_s)
  rescue StandardError
    nil
  end
  return [nil, true] if casted.any?(&:nil?) && elements.any?

  [casted.presence, false]
end

#validate_typed_value(record, val) ⇒ Object



29
30
31
# File 'app/models/typed_eav/field/date_array.rb', line 29

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