Class: WorkerTools::Utils::SerializedArrayType

Inherits:
ActiveRecord::Type::Json
  • Object
show all
Defined in:
lib/worker_tools/utils/serialized_array_type.rb

Instance Method Summary collapse

Constructor Details

#initialize(type: nil) ⇒ SerializedArrayType

Returns a new instance of SerializedArrayType.



4
5
6
# File 'lib/worker_tools/utils/serialized_array_type.rb', line 4

def initialize(type: nil)
  @type = type
end

Instance Method Details

#deserialize(value) ⇒ Object



8
9
10
# File 'lib/worker_tools/utils/serialized_array_type.rb', line 8

def deserialize(value)
  super(value)&.map { |d| @type.deserialize(d) }
end

#serialize(value) ⇒ Object



12
13
14
15
16
# File 'lib/worker_tools/utils/serialized_array_type.rb', line 12

def serialize(value)
  raise 'not an array' unless value.is_a?(Array)

  super value
end