Class: Types::CompactedIntArrayType
- Inherits:
-
ActiveModel::Type::Value
- Object
- ActiveModel::Type::Value
- Types::CompactedIntArrayType
- Defined in:
- app/lib/types/compacted_int_array_type.rb
Overview
ActiveModel::Type replacement for Virtus::CompactedIntArray.
Accepts any value, flattens it into an array, removes blanks, and casts
each remaining element to Integer (silently discards non-integer entries).
Instance Method Summary collapse
Instance Method Details
#cast(value) ⇒ Object
9 10 11 12 13 14 15 |
# File 'app/lib/types/compacted_int_array_type.rb', line 9 def cast(value) [(value.presence || [])].flatten.map(&:presence).filter_map do |v| Integer(v) rescue ArgumentError, TypeError nil end end |
#changed_in_place?(raw_old, new_val) ⇒ Boolean
17 18 19 |
# File 'app/lib/types/compacted_int_array_type.rb', line 17 def changed_in_place?(raw_old, new_val) cast(raw_old) != cast(new_val) end |
#type ⇒ Object
7 |
# File 'app/lib/types/compacted_int_array_type.rb', line 7 def type = :compacted_int_array |