lib/lockbox/model.rb in lockbox-1.1.1 vs lib/lockbox/model.rb in lockbox-1.1.2
- old
+ new
@@ -541,12 +541,12 @@
end
when :string, :binary
# do nothing
# encrypt will convert to binary
else
- # use original name for serialized attributes
- type = (try(:attribute_types) || {})[original_name.to_s]
+ # use original name for serialized attributes if no type specified
+ type = (try(:attribute_types) || {})[(options[:type] ? name : original_name).to_s]
message = type.serialize(message) if type
end
end
if message.nil? || (message == "" && !options[:padding])
@@ -574,13 +574,13 @@
when :datetime
message = ActiveRecord::Type::DateTime.new.deserialize(message)
when :time
message = ActiveRecord::Type::Time.new.deserialize(message)
when :integer
- message = ActiveRecord::Type::Integer.new(limit: 8).deserialize(message.unpack("q>").first)
+ message = ActiveRecord::Type::Integer.new(limit: 8).deserialize(message.unpack1("q>"))
when :float
- message = ActiveRecord::Type::Float.new.deserialize(message.unpack("G").first)
+ message = ActiveRecord::Type::Float.new.deserialize(message.unpack1("G"))
when :string
message.force_encoding(Encoding::UTF_8)
when :binary
# do nothing
# decrypt returns binary string
@@ -588,11 +588,11 @@
family, prefix, addr = message.unpack("CCa16")
len = family == 0 ? 4 : 16
message = IPAddr.new_ntoh(addr.first(len))
message.prefix = prefix
else
- # use original name for serialized attributes
- type = (try(:attribute_types) || {})[original_name.to_s]
+ # use original name for serialized attributes if no type specified
+ type = (try(:attribute_types) || {})[(options[:type] ? name : original_name).to_s]
message = type.deserialize(message) if type
message.force_encoding(Encoding::UTF_8) if !type || type.is_a?(ActiveModel::Type::String)
end
end