Init dump
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
class ArrayOfItemsType < ActiveModel::Type::Value
|
||||
# The `cast` method is used to convert an incoming value into the desired type.
|
||||
def cast(value)
|
||||
return unless value.present?
|
||||
|
||||
Array.wrap(value).map do |item_data|
|
||||
# Assuming item_data is a hash, this creates an instance of the Item class.
|
||||
# You can modify this part to match your object's initializer.
|
||||
if item_data.is_a?(Hash)
|
||||
Item.new(item_data)
|
||||
else
|
||||
item_data # Return the item as-is if it's already an object
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# This method is used when defining the type to convert it to a string for serialization.
|
||||
def serialize(value)
|
||||
value
|
||||
end
|
||||
end
|
||||
|
||||
ActiveModel::Type.register(:array_of_items, ArrayOfItemsType)
|
||||
Reference in New Issue
Block a user