Module: Ghaki::Account::Username
Constant Summary collapse
- USERNAME_RETRY_MAX =
CONSTANTS
3
Instance Attribute Summary collapse
-
#username ⇒ Object
OBJECT METHODS.
Class Method Summary collapse
-
.get_env ⇒ Object
———————————————————————.
Instance Method Summary collapse
-
#ask_username(opts = {}) ⇒ Object
———————————————————————.
-
#valid_username? ⇒ Boolean
———————————————————————.
Methods included from SynOpts
Instance Attribute Details
#username ⇒ Object
OBJECT METHODS
33 34 35 |
# File 'lib/ghaki/account/username.rb', line 33 def username @username end |
Class Method Details
.get_env ⇒ Object
26 27 28 |
# File 'lib/ghaki/account/username.rb', line 26 def Username.get_env Etc.getlogin end |
Instance Method Details
#ask_username(opts = {}) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ghaki/account/username.rb', line 56 def ask_username opts={} f_ques,r_ques = _username_prompt(opts), nil defval = opts[:default] || @username defval = Username.get_env if defval == :env (1 .. (opts[:retry_max] || USERNAME_RETRY_MAX) ).each do @username = HighLine.new.ask( r_ques || f_ques ) do |q| q.echo = true q.default = defval unless defval.nil? end return @username if valid_username? r_ques ||= '* TRY AGAIN * ' + f_ques end raise InvalidUsernameError, "Invalid Username: #{@username}" end |
#valid_username? ⇒ Boolean
48 49 50 51 52 53 |
# File 'lib/ghaki/account/username.rb', line 48 def valid_username? return false if @username.nil? return false if @username.empty? return false unless @username =~ %r{\A\S+\z}o return true end |