class PGTrunk::Serializers::ArrayOfHashesSerializer
@private Cast the attribute value as an array of strings. It knows how to cast arrays returned by PostgreSQL as a string like ‘{USD,EUR,GBP}’ into [‘USD’, ‘EUR’, ‘GBP’].
Public Instance Methods
cast(value)
click to toggle source
# File lib/pg_trunk/core/serializers/array_of_hashes_serializer.rb, line 10 def cast(value) case value when ::String then JSON.parse(value).map(&:symbolize_keys) when ::NilClass then [] when ::Array then value.map(&:to_h) else [value.to_h] end end
serialize(value)
click to toggle source
# File lib/pg_trunk/core/serializers/array_of_hashes_serializer.rb, line 19 def serialize(value) Array.wrap(value).map { |item| item.to_h.symbolize_keys } end