Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-05-15 15:34:22 +0300
committerDouwe Maan <douwe@gitlab.com>2015-05-15 15:34:22 +0300
commitb77e1ae6f78461a1721150538158480d99bd899b (patch)
tree2a70e9bb63ea0f21414ab6436c476af61ecd9b23 /config
parent25b0968846700d762b034fdb26c9beab461a4b1c (diff)
Don't require DB conncetion in AttrEncrypted.
Diffstat (limited to 'config')
-rw-r--r--config/initializers/attr_encrypted_no_db_connection.rb29
1 files changed, 29 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..72e257a013e
--- /dev/null
+++ b/config/initializers/attr_encrypted_no_db_connection.rb
@@ -0,0 +1,29 @@
+module AttrEncrypted
+ module Adapters
+ module ActiveRecord
+ protected
+
+ def attribute_instance_methods_as_symbols
+ # We add accessor methods of the db columns to the list of instance
+ # methods returned to let ActiveRecord define the accessor methods
+ # for the db columns
+ if connection_established? && table_exists?
+ columns_hash.keys.inject(super) {|instance_methods, column_name| instance_methods.concat [column_name.to_sym, :"#{column_name}="]}
+ else
+ super
+ end
+ end
+
+ def connection_established?
+ begin
+ # use with_connection so the connection doesn't stay pinned to the thread.
+ ActiveRecord::Base.connection_pool.with_connection {
+ ActiveRecord::Base.connection.active?
+ }
+ rescue Exception
+ false
+ end
+ end
+ end
+ end
+end