Class: Generamba::UserPreferences

Inherits:
Object
  • Object
show all
Defined in:
lib/generamba/configuration/user_preferences.rb

Overview

A class that provides methods for working with user-specific information. Currently it has methods for obtaining and saving username, later it may be improved to something more general.

Class Method Summary collapse

Class Method Details

.obtain_usernameObject



9
10
11
12
13
14
15
16
# File 'lib/generamba/configuration/user_preferences.rb', line 9

def self.obtain_username
  path = obtain_user_preferences_path

  file_contents = open(path).read
  preferences = file_contents.empty? ? {} : YAML.load(file_contents).to_hash

  return preferences[USERNAME_KEY]
end

.save_username(username) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/generamba/configuration/user_preferences.rb', line 18

def self.save_username(username)
  path = obtain_user_preferences_path

  file_contents = open(path).read
  preferences = file_contents.empty? ? {} : YAML.load(file_contents).to_hash

  preferences[USERNAME_KEY] = username
  File.open(path, 'w+') { |f| f.write(preferences.to_yaml) }
end