Class: Pixiurge::Authentication::FileAccountStorage
- Inherits:
-
AccountStorage
- Object
- AccountStorage
- Pixiurge::Authentication::FileAccountStorage
- Defined in:
- lib/pixiurge/authentication.rb
Overview
Store account data as a JSON file. Not multithread-safe. This is the default built-in account storage if you don't specify.
Instance Method Summary collapse
-
#data_for(username) ⇒ Hash{String=>String}?
Get user data for the named account.
-
#initialize(pathname, oldpathname = pathname + ".old") ⇒ FileAccountStorage
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(pathname, oldpathname = pathname + ".old") ⇒ FileAccountStorage
Constructor
307 308 309 310 311 312 |
# File 'lib/pixiurge/authentication.rb', line 307 def initialize(pathname, oldpathname = pathname + ".old") @accounts_json_filename = pathname @accounts_old_json_filename = oldpathname sync_account_state end |
Instance Method Details
#data_for(username) ⇒ Hash{String=>String}?
Get user data for the named account.
332 333 334 |
# File 'lib/pixiurge/authentication.rb', line 332 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.
322 323 324 325 |
# File 'lib/pixiurge/authentication.rb', line 322 def register(username, account_data) @account_state[username] = account_data sync_account_state 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.
344 345 346 347 |
# File 'lib/pixiurge/authentication.rb', line 344 def set_data_for(username, new_data) @account_state[username] = new_data sync_account_state end |
#unregister(username) ⇒ void
This method returns an undefined value.
Unregister the named account; delete it from the AccountStorage.
354 355 356 357 358 359 360 |
# File 'lib/pixiurge/authentication.rb', line 354 def unregister(username) unless @account_state[username] raise "No such account username as #{username.inspect}!" end @account_state.delete(username) sync_account_state end |