Module: Meshchat::Configuration::Identity
- Defined in:
- lib/meshchat/configuration/identity.rb
Class Method Summary collapse
- .alert_and_exit ⇒ Object
- .ask_for_alias ⇒ Object
- .check_or_create(overwrite = false, auto_confirm = false) ⇒ Object
- .confirm?(msg) ⇒ Boolean
- .confirm_alias ⇒ Object
- .confirm_keys ⇒ Object
- .confirm_uid ⇒ Object
- .generate! ⇒ Object
- .setup_is_completed? ⇒ Boolean
Class Method Details
.alert_and_exit ⇒ Object
23 24 25 26 |
# File 'lib/meshchat/configuration/identity.rb', line 23 def alert_and_exit Display.alert I18n.t('identity.settings_are_invalid') exit(1) end |
.ask_for_alias ⇒ Object
64 65 66 67 68 69 |
# File 'lib/meshchat/configuration/identity.rb', line 64 def ask_for_alias Display.add_line I18n.t('identity.ask_for_alias') response = gets response = response.chomp APP_CONFIG.user['alias'] = response end |
.check_or_create(overwrite = false, auto_confirm = false) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/meshchat/configuration/identity.rb', line 7 def check_or_create(overwrite = false, auto_confirm = false) # if setup is complete, we don't need to do anything. # it's likely the user already went through the setup process return if setup_is_completed? && !overwrite generate! if auto_confirm || confirm?(I18n.t('identity.settings_not_detected')) # if everything is good, the app can boot return APP_CONFIG.user.save if setup_is_completed? # if something has gone wrong, we'll ask if they want to try again return check_or_create(true, true) if confirm? I18n.t('identity.unknown_error_try_again') # we failed, and don't want to continue alert_and_exit end |
.confirm?(msg) ⇒ Boolean
71 72 73 74 75 76 |
# File 'lib/meshchat/configuration/identity.rb', line 71 def confirm?(msg) Display.warning msg + I18n.t(:confirm_options) response = gets response = response.chomp [I18n.t(:confirm_yes), I18n.t(:confirm_y)].include?(response.downcase) end |
.confirm_alias ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/meshchat/configuration/identity.rb', line 47 def confirm_alias if APP_CONFIG.user['alias'].present? Display.add_line I18.t('idenity.current_alias', name: APP_CONFIG.user['alias']) ask_for_alias if confirm? I18n.t('identity.confirm_alias_replace') else ask_for_alias end end |
.confirm_keys ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/meshchat/configuration/identity.rb', line 56 def confirm_keys if APP_CONFIG.user.keys_exist? APP_CONFIG.user.generate_keys if confirm? I18n.t('identity.confirm_key_replace') else APP_CONFIG.user.generate_keys end end |
.confirm_uid ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/meshchat/configuration/identity.rb', line 39 def confirm_uid if APP_CONFIG.user.uid_exists? APP_CONFIG.user.generate_uid if confirm? I18n.t('identity.confirm_uid_replace') else APP_CONFIG.user.generate_uid end end |
.generate! ⇒ Object
32 33 34 35 36 37 |
# File 'lib/meshchat/configuration/identity.rb', line 32 def generate! confirm_uid confirm_alias confirm_keys # TODO: port and ip? end |
.setup_is_completed? ⇒ Boolean
28 29 30 |
# File 'lib/meshchat/configuration/identity.rb', line 28 def setup_is_completed? APP_CONFIG.user.is_complete? end |