diff --git a/lib/attr_encrypted/adapters/active_record.rb b/lib/attr_encrypted/adapters/active_record.rb index 62cec13d..c1ee258a 100644 --- a/lib/attr_encrypted/adapters/active_record.rb +++ b/lib/attr_encrypted/adapters/active_record.rb @@ -6,19 +6,18 @@ module Adapters module ActiveRecord RAILS_VERSION = Gem::Version.new(::ActiveRecord::VERSION::STRING).freeze - def self.extended(base) # :nodoc: - base.class_eval do - - # https://github.com/attr-encrypted/attr_encrypted/issues/68 - alias_method :reload_without_attr_encrypted, :reload - def reload(*args, &block) - result = reload_without_attr_encrypted(*args, &block) - self.class.attr_encrypted_encrypted_attributes.keys.each do |attribute_name| - instance_variable_set("@#{attribute_name}", nil) - end - result + module Reload + def reload(...) + result = super + self.class.attr_encrypted_encrypted_attributes.keys.each do |attribute_name| + instance_variable_set("@#{attribute_name}", nil) end + result + end + end + def self.extended(base) # :nodoc: + base.class_eval do attr_encrypted_options[:encode] = true class << self @@ -148,5 +147,6 @@ def method_missing_with_attr_encrypted(method, *args, &block) ActiveSupport.on_load(:active_record) do extend AttrEncrypted extend AttrEncrypted::Adapters::ActiveRecord + prepend AttrEncrypted::Adapters::ActiveRecord::Reload end end