lib/lockbox/model.rb in lockbox-1.3.0 vs lib/lockbox/model.rb in lockbox-1.3.1
- old
+ new
@@ -322,17 +322,27 @@
end
attribute name, attribute_type
if ActiveRecord::VERSION::STRING.to_f >= 7.1
- serialize name, coder: JSON if options[:type] == :json
- serialize name, type: Hash if options[:type] == :hash
- serialize name, type: Array if options[:type] == :array
+ case options[:type]
+ when :json
+ serialize name, coder: JSON
+ when :hash
+ serialize name, type: Hash, coder: default_column_serializer || YAML
+ when :array
+ serialize name, type: Array, coder: default_column_serializer || YAML
+ end
else
- serialize name, JSON if options[:type] == :json
- serialize name, Hash if options[:type] == :hash
- serialize name, Array if options[:type] == :array
+ case options[:type]
+ when :json
+ serialize name, JSON
+ when :hash
+ serialize name, Hash
+ when :array
+ serialize name, Array
+ end
end
elsif !attributes_to_define_after_schema_loads.key?(name.to_s)
# when migrating it's best to specify the type directly
# however, we can try to use the original type if its already defined
if attributes_to_define_after_schema_loads.key?(original_name.to_s)
@@ -613,9 +623,13 @@
message = IPAddr.new_ntoh(addr.first(len))
message.prefix = prefix
else
# use original name for serialized attributes if no type specified
type = (try(:attribute_types) || {})[(options[:type] ? name : original_name).to_s]
+ # for Action Text
+ if activerecord && type.is_a?(ActiveRecord::Type::Serialized) && defined?(ActionText::Content) && type.coder == ActionText::Content
+ message.force_encoding(Encoding::UTF_8)
+ end
message = type.deserialize(message) if type
message.force_encoding(Encoding::UTF_8) if !type || type.is_a?(ActiveModel::Type::String)
end
end