Module: Db2Session::Manager
- Included in:
- ApplicationController
- Defined in:
- lib/db2_session/manager.rb
Constant Summary collapse
- @@sessions =
Concurrent::Map.new
- @@hmac_secret =
SecureRandom.hex(64)
Instance Method Summary collapse
- #authenticate! ⇒ Object
- #create_new_connection ⇒ Object
- #db2_config ⇒ Object
- #flush_idling_connections! ⇒ Object
Instance Method Details
#authenticate! ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/db2_session/manager.rb', line 15 def authenticate! Thread.current[:connection] = current_connection yield rescue Exception => e render json: { message: e. }, status: :unauthorized ensure Thread.current[:connection] = nil end |
#create_new_connection ⇒ Object
24 25 26 27 28 |
# File 'lib/db2_session/manager.rb', line 24 def create_new_connection new_session_connection.tap do |connection| sessions.fetch_or_store(connection.object_id, connection) end end |
#db2_config ⇒ Object
11 12 13 |
# File 'lib/db2_session/manager.rb', line 11 def db2_config Db2Query::Base.config end |
#flush_idling_connections! ⇒ Object
30 31 32 33 34 |
# File 'lib/db2_session/manager.rb', line 30 def flush_idling_connections! sessions.each_pair do |key, conn| sessions.delete_pair(key, conn) if idle_connection?(conn) end end |