Class: Pixiurge::Authentication::MemStorage
- Inherits:
-
AccountStorage
- Object
- AccountStorage
- Pixiurge::Authentication::MemStorage
- Defined in:
- lib/pixiurge/authentication.rb
Overview
Store account data as a Hash in memory. Does not persist across reboots. This is intended for testing, not production.
Instance Attribute Summary collapse
-
#account_state ⇒ Object
readonly
Only for testing, but then so is this storage method.
Instance Method Summary collapse
-
#data_for(username) ⇒ Hash{String=>String}?
Get user data for the named account.
-
#initialize ⇒ MemStorage
constructor
Constructor.
-
#register(username, account_data) ⇒ void
Create an account.
-
#set_data_for(username, new_data) ⇒ void
Set user data for the named account.
-
#unregister(username) ⇒ void
Unregister the named account; delete it from the AccountStorage.
Constructor Details
#initialize ⇒ MemStorage
Constructor
394 395 396 |
# File 'lib/pixiurge/authentication.rb', line 394 def initialize @account_state = {} end |
Instance Attribute Details
#account_state ⇒ Object (readonly)
Only for testing, but then so is this storage method
389 390 391 |
# File 'lib/pixiurge/authentication.rb', line 389 def account_state @account_state end |
Instance Method Details
#data_for(username) ⇒ Hash{String=>String}?
Get user data for the named account.
415 416 417 |
# File 'lib/pixiurge/authentication.rb', line 415 def data_for(username) @account_state[username] end |
#register(username, account_data) ⇒ void
This method returns an undefined value.
Create an account. The account_data hash will contain information about the encrypted password hash in the default setup, but it's allowed to contain any JSON-serializable Hash in general.
406 407 408 |
# File 'lib/pixiurge/authentication.rb', line 406 def register(username, account_data) @account_state[username] = account_data end |
#set_data_for(username, new_data) ⇒ void
This method returns an undefined value.
Set user data for the named account. Any fields not included in the new value are deleted. Raise an error if the username does not exist.
427 428 429 |
# File 'lib/pixiurge/authentication.rb', line 427 def set_data_for(username, new_data) @account_state[username] = new_data end |
#unregister(username) ⇒ void
This method returns an undefined value.
Unregister the named account; delete it from the AccountStorage.
436 437 438 439 440 441 |
# File 'lib/pixiurge/authentication.rb', line 436 def unregister(username) unless @account_state[username] raise "No such account username as #{username.inspect}!" end @account_state.delete(username) end |