Class: TypedEAV::Field::DecimalArray

Inherits:
Base show all
Defined in:
app/models/typed_eav/field/decimal_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/decimal_array.rb', line 11

def array_field? = true

#cast(raw) ⇒ Object

See IntegerArray#cast for the “invalid element → whole value invalid” rationale. Same pattern: any unparseable element marks the cast invalid and stores nil rather than a silently-pruned partial.



16
17
18
19
20
21
22
23
24
# File 'app/models/typed_eav/field/decimal_array.rb', line 16

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 { |v| BigDecimal(v.to_s, exception: false) }
  return [nil, true] if casted.any?(&:nil?) && elements.any?

  [casted.presence, false]
end

#validate_typed_value(record, val) ⇒ Object



26
27
28
# File 'app/models/typed_eav/field/decimal_array.rb', line 26

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