Class: Pixiurge::Authentication::MemStorage

Inherits:
AccountStorage show all
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.

Since:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMemStorage

Constructor

Since:

  • 0.1.0



394
395
396
# File 'lib/pixiurge/authentication.rb', line 394

def initialize
  @account_state = {}
end

Instance Attribute Details

#account_stateObject (readonly)

Only for testing, but then so is this storage method

Since:

  • 0.1.0



389
390
391
# File 'lib/pixiurge/authentication.rb', line 389

def 
  @account_state
end

Instance Method Details

#data_for(username) ⇒ Hash{String=>String}?

Get user data for the named account.

Parameters:

  • username (String)

    The account's username

Returns:

  • (Hash{String=>String}, nil)

    The account's user data or nil if it does not exist

Since:

  • 0.1.0



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.

Parameters:

  • username (String)

    The account's username; see AuthenticatedApp::USERNAME_REGEX for legal format

  • account_data (Hash{String})

    The user's data, normally including login info

Since:

  • 0.1.0



406
407
408
# File 'lib/pixiurge/authentication.rb', line 406

def register(username, )
  @account_state[username] = 
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.

Parameters:

  • username (String)

    The account's username

  • new_data (Hash{String=>String})

    The account's new user data

Since:

  • 0.1.0



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.

Parameters:

  • username (String)

    The account's username

Since:

  • 0.1.0



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