Module: Ghaki::Account::Username

Extended by:
SynOpts
Included in:
Base
Defined in:
lib/ghaki/account/username.rb

Constant Summary collapse

USERNAME_RETRY_MAX =

CONSTANTS

3

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SynOpts

attr_syn_opts

Instance Attribute Details

#usernameObject

OBJECT METHODS



33
34
35
# File 'lib/ghaki/account/username.rb', line 33

def username
  @username
end

Class Method Details

.get_envObject




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


Returns:

  • (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