Module: Ghaki::Account::Hostname
Constant Summary collapse
- HOSTNAME_RETRY_MAX =
CONSTANTS
3
Instance Attribute Summary collapse
-
#hostname ⇒ Object
OBJECT METHODS.
Class Method Summary collapse
-
.get_env ⇒ Object
———————————————————————.
Instance Method Summary collapse
-
#ask_hostname(opts = {}) ⇒ Object
———————————————————————.
-
#valid_hostname? ⇒ Boolean
———————————————————————.
Methods included from SynOpts
Instance Attribute Details
#hostname ⇒ Object
OBJECT METHODS
39 40 41 |
# File 'lib/ghaki/account/hostname.rb', line 39 def hostname @hostname end |
Class Method Details
.get_env ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/ghaki/account/hostname.rb', line 27 def Hostname.get_env if ENV.has_key?('HOSTNAME') ENV['HOSTNAME'] else require 'socket' Socket.gethostname end end |
Instance Method Details
#ask_hostname(opts = {}) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ghaki/account/hostname.rb', line 62 def ask_hostname opts={} o_prompt,r_prompt = _hostname_prompt(opts), nil defval = opts[:default] || @hostname defval = Hostname.get_env if defval == :env (1 .. (opts[:retry_max] || HOSTNAME_RETRY_MAX) ).each do self.hostname = HighLine.new.ask( r_prompt||o_prompt ) do |q| q.echo = true q.default = defval unless defval.nil? end return @hostname if valid_hostname? r_prompt ||= '* TRY AGAIN * ' + o_prompt end raise InvalidHostnameError, "Invalid Hostname: #{@hostname}" end |
#valid_hostname? ⇒ Boolean
54 55 56 57 58 59 |
# File 'lib/ghaki/account/hostname.rb', line 54 def valid_hostname? return false if @hostname.nil? return false if @hostname.empty? return false unless @hostname =~ %r{\A\S+\z}o return true end |