Skip to content

Commit

Permalink
Switch back to DelegateClass(ActiveModel::Type::Value)
Browse files Browse the repository at this point in the history
Thanks to @rafaelfranca for the suggestion.
  • Loading branch information
djmb committed Aug 22, 2024
1 parent b234a94 commit 3fb30db
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,15 @@ def encrypt_attribute(name, key_provider: nil, key: nil, deterministic: false, s
scheme = scheme_for key_provider: key_provider, key: key, deterministic: deterministic, support_unencrypted_data: support_unencrypted_data, \
downcase: downcase, ignore_case: ignore_case, previous: previous, compress: compress, compressor: compressor, **context_properties

type_options = { scheme: scheme, default: columns_hash[name.to_s]&.default }
if cast_type.serialized?
cast_type.tap do |serialized_type|
serialized_type.replace_serialized_subtype do |current_subtype|
ActiveRecord::Encryption::EncryptedAttributeType.new(scheme: scheme, cast_type: current_subtype, default: columns_hash[name.to_s]&.default)
ActiveRecord::Encryption::EncryptedAttributeType.new(cast_type: current_subtype, **type_options)
end
end
else
ActiveRecord::Encryption::EncryptedAttributeType.new(scheme: scheme, cast_type: cast_type, default: columns_hash[name.to_s]&.default)
ActiveRecord::Encryption::EncryptedAttributeType.new(cast_type: cast_type, **type_options)
end
end

Expand Down
5 changes: 3 additions & 2 deletions activerecord/lib/active_record/type/serialized.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module ActiveRecord
module Type
class Serialized < SimpleDelegator # :nodoc:
class Serialized < DelegateClass(ActiveModel::Type::Value) # :nodoc:
undef to_yaml if method_defined?(:to_yaml)

include ActiveModel::Type::Helpers::Mutable
Expand All @@ -12,7 +12,7 @@ class Serialized < SimpleDelegator # :nodoc:
def initialize(subtype, coder)
@subtype = subtype
@coder = coder
__setobj__(subtype)
super(subtype)
end

def init_with(coder) # :nodoc:
Expand Down Expand Up @@ -67,6 +67,7 @@ def serialized? # :nodoc:
def replace_serialized_subtype(&block) # :nodoc:
@subtype = block.call(subtype)
__setobj__(@subtype)
self
end

private
Expand Down

0 comments on commit 3fb30db

Please sign in to comment.