Class: DecisionAgent::Auth::InMemoryUserStore
- Inherits:
-
Object
- Object
- DecisionAgent::Auth::InMemoryUserStore
- Defined in:
- lib/decision_agent/auth/authenticator.rb
Overview
In-memory user store (can be replaced with ActiveRecord adapter later)
Instance Method Summary collapse
- #all ⇒ Object
- #delete(id) ⇒ Object
- #find_by_email(email) ⇒ Object
- #find_by_id(id) ⇒ Object
-
#initialize ⇒ InMemoryUserStore
constructor
A new instance of InMemoryUserStore.
- #save(user) ⇒ Object
Constructor Details
#initialize ⇒ InMemoryUserStore
Returns a new instance of InMemoryUserStore.
88 89 90 91 92 |
# File 'lib/decision_agent/auth/authenticator.rb', line 88 def initialize @users = {} @users_by_email = {} @mutex = Mutex.new end |
Instance Method Details
#all ⇒ Object
114 115 116 117 118 |
# File 'lib/decision_agent/auth/authenticator.rb', line 114 def all @mutex.synchronize do @users.values.dup end end |
#delete(id) ⇒ Object
120 121 122 123 124 125 126 |
# File 'lib/decision_agent/auth/authenticator.rb', line 120 def delete(id) @mutex.synchronize do user = @users.delete(id) @users_by_email.delete(user.email.downcase) if user user end end |
#find_by_email(email) ⇒ Object
108 109 110 111 112 |
# File 'lib/decision_agent/auth/authenticator.rb', line 108 def find_by_email(email) @mutex.synchronize do @users_by_email[email.downcase] end end |
#find_by_id(id) ⇒ Object
102 103 104 105 106 |
# File 'lib/decision_agent/auth/authenticator.rb', line 102 def find_by_id(id) @mutex.synchronize do @users[id] end end |
#save(user) ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/decision_agent/auth/authenticator.rb', line 94 def save(user) @mutex.synchronize do @users[user.id] = user @users_by_email[user.email.downcase] = user end user end |