2015-05-15 08:34:22 -04:00
|
|
|
module AttrEncrypted
|
|
|
|
module Adapters
|
|
|
|
module ActiveRecord
|
2015-05-15 08:56:04 -04:00
|
|
|
def attribute_instance_methods_as_symbols_with_no_db_connection
|
2015-05-15 09:32:49 -04:00
|
|
|
# Use with_connection so the connection doesn't stay pinned to the thread.
|
|
|
|
connected = ::ActiveRecord::Base.connection_pool.with_connection(&:active?) rescue false
|
|
|
|
|
|
|
|
if connected
|
2015-05-15 08:56:04 -04:00
|
|
|
# Call version from AttrEncrypted::Adapters::ActiveRecord
|
|
|
|
attribute_instance_methods_as_symbols_without_no_db_connection
|
2015-05-15 08:34:22 -04:00
|
|
|
else
|
2015-05-15 09:32:49 -04:00
|
|
|
# Call version from AttrEncrypted, i.e., `super` with regards to AttrEncrypted::Adapters::ActiveRecord
|
2015-05-15 08:56:04 -04:00
|
|
|
AttrEncrypted.instance_method(:attribute_instance_methods_as_symbols).bind(self).call
|
2015-05-15 08:34:22 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-05-15 08:56:04 -04:00
|
|
|
alias_method_chain :attribute_instance_methods_as_symbols, :no_db_connection
|
2015-05-15 08:34:22 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|