Skip to content

Commit 456b844

Browse files
authored
Prevent attr_encrypted from making queries on load
`#attribute_instance_methods_as_symbols` can trigger a query when the schema cache is not loaded. We only need the results of this method if `attribute_instance_methods_as_symbols_available?` is true so we move this inside the check. Signed-off-by: Bojan Marjanovic <[email protected]>
1 parent c2aa160 commit 456b844

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

lib/attr_encrypted.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,8 @@ def attr_encrypted(*attributes)
144144
attributes.each do |attribute|
145145
encrypted_attribute_name = (options[:attribute] ? options[:attribute] : [options[:prefix], attribute, options[:suffix]].join).to_sym
146146

147-
instance_methods_as_symbols = attribute_instance_methods_as_symbols
148-
149147
if attribute_instance_methods_as_symbols_available?
148+
instance_methods_as_symbols = attribute_instance_methods_as_symbols
150149
attr_reader encrypted_attribute_name unless instance_methods_as_symbols.include?(encrypted_attribute_name)
151150
attr_writer encrypted_attribute_name unless instance_methods_as_symbols.include?(:"#{encrypted_attribute_name}=")
152151

0 commit comments

Comments
 (0)