summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-05-15 14:39:38 +0000
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-05-15 17:45:15 +0300
commit4b686755b2dcd04beb63ac34cb4cbe69e83c899f (patch)
tree110b16be849ec6f6a0ed8f5f1b9aaaab5d487ab6
parentf980dc4f60af711f73e5c5e397c1e3a57dc5deea (diff)
downloadgitlab-ce-4b686755b2dcd04beb63ac34cb4cbe69e83c899f.tar.gz
Merge branch 'attr_encryped_no_db_connection' into 'master'
Don't require DB connection in AttrEncrypted. See merge request !667
-rw-r--r--config/initializers/attr_encrypted_no_db_connection.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/config/initializers/attr_encrypted_no_db_connection.rb b/config/initializers/attr_encrypted_no_db_connection.rb
new file mode 100644
index 00000000000..c668864089b
--- /dev/null
+++ b/config/initializers/attr_encrypted_no_db_connection.rb
@@ -0,0 +1,20 @@
+module AttrEncrypted
+ module Adapters
+ module ActiveRecord
+ def attribute_instance_methods_as_symbols_with_no_db_connection
+ # 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
+ attribute_instance_methods_as_symbols_without_no_db_connection
+ 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
+
+ alias_method_chain :attribute_instance_methods_as_symbols, :no_db_connection
+ end
+ end
+end