debian-mirror-gitlab/config/initializers/attr_encrypted_no_db_connection.rb
2016-11-03 12:29:30 +05:30

21 lines
758 B
Ruby

module AttrEncrypted
module Adapters
module ActiveRecord
module DBConnectionQuerier
def attribute_instance_methods_as_symbols
# 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
# Call version from AttrEncrypted::Adapters::ActiveRecord
super
else
# Call version from AttrEncrypted, i.e., `super` with regards to AttrEncrypted::Adapters::ActiveRecord
AttrEncrypted.instance_method(:attribute_instance_methods_as_symbols).bind(self).call
end
end
end
prepend DBConnectionQuerier
end
end
end