Class: Ghaki::Account::Base

Inherits:
Object
  • Object
show all
Includes:
EMailAddress, Hostname, Password, Username
Defined in:
lib/ghaki/account/base.rb

Direct Known Subclasses

Database, WinDos

Constant Summary

Constants included from Password

Password::ASK_PASSWORD_RETRY_MAX

Constants included from Username

Username::USERNAME_RETRY_MAX

Constants included from Hostname

Hostname::HOSTNAME_RETRY_MAX

Instance Attribute Summary

Attributes included from EMailAddress

#email_address

Attributes included from Username

#username

Attributes included from Hostname

#hostname

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SynOpts

#attr_syn_opts

Methods included from Password

#ask_password, #fail_password, #failed_passwords?, #opt_password, #password, #passwords, #passwords=, #reset_passwords, #retry_password?, #valid_password?

Methods included from Username

#ask_username, get_env, #valid_username?

Methods included from Hostname

#ask_hostname, get_env, #valid_hostname?

Constructor Details

#initialize(opts = {}) ⇒ Base

OBJECT METHODS



37
38
39
# File 'lib/ghaki/account/base.rb', line 37

def initialize opts={}
  _from_opts opts
end

Class Method Details

.from_opts(opts) ⇒ Object

CLASS METHODS



20
21
22
# File 'lib/ghaki/account/base.rb', line 20

def self.from_opts opts
  opts[:account] || Base.new(opts)
end

.purge_opts(opts) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/ghaki/account/base.rb', line 24

def self.purge_opts opts
  Hostname.purge_opts opts
  Username.purge_opts opts
  Password.purge_opts opts
  EMailAddress.purge_opts opts
  opts.delete(:account)
  opts
end

Instance Method Details

#ask_all(opts = {}) ⇒ Object



60
61
62
63
64
# File 'lib/ghaki/account/base.rb', line 60

def ask_all opts={}
  ask_hostname opts[:hostname_opts] || {}
  ask_username opts[:username_opts] || {}
  ask_password opts[:password_opts] || {}
end

#collapse_opts(opts = {}) ⇒ Object



50
51
52
53
54
# File 'lib/ghaki/account/base.rb', line 50

def collapse_opts opts={}
  self.class.purge_opts opts
  opts[:account] = self
  opts
end

#expand_opts(opts = {}) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/ghaki/account/base.rb', line 41

def expand_opts opts={}
  opts.delete(:account)
  opts[:hostname] = @hostname unless @hostname.nil?
  opts[:username] = @username unless @username.nil?
  opts[:password] = self.passwords unless passwords.empty?
  opts[:email_address] = @email_address unless @email_address.nil?
  opts
end

#to_sObject



56
57
58
# File 'lib/ghaki/account/base.rb', line 56

def to_s
  (@username || '*') + '@' + (@hostname || '*')
end