Class: Redwood::AccountManager

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/sup/account.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(accounts) ⇒ AccountManager

Returns a new instance of AccountManager.



18
19
20
21
22
23
24
25
26
27
# File 'lib/sup/account.rb', line 18

def initialize accounts
  @email_map = {}
  @accounts = {}
  @default_account = nil

   accounts[:default], true
  accounts.each { |k, v|  v unless k == :default }

  self.class.i_am_the_instance self
end

Instance Attribute Details

#default_accountObject

Returns the value of attribute default_account.



16
17
18
# File 'lib/sup/account.rb', line 16

def 
  @default_account
end

Instance Method Details

#account_for(email) ⇒ Object



57
# File 'lib/sup/account.rb', line 57

def  email; @email_map[email] end

#add_account(hash, default = false) ⇒ Object

must be called first with the default account. fills in missing values from the default account.

Raises:

  • (ArgumentError)


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/sup/account.rb', line 34

def  hash, default=false
  raise ArgumentError, "no email specified for account" unless hash[:email]
  unless default
    [:name, :sendmail, :signature].each { |k| hash[k] ||= @default_account.send(k) }
  end
  hash[:alternates] ||= []

  main_email = hash[:email]
  ([hash[:email]] + hash[:alternates]).each do |email|
    next if @email_map.member? email
    a = Account.new main_email, hash
    PersonManager.register a
    @accounts[a] = true
    @email_map[email] = a
  end

  if default
    raise ArgumentError, "multiple default accounts" if @default_account
    @default_account = @email_map[main_email]
  end
end

#is_account?(p) ⇒ Boolean

Returns:

  • (Boolean)


56
# File 'lib/sup/account.rb', line 56

def is_account? p;  p.email end

#is_account_email?(email) ⇒ Boolean

Returns:

  • (Boolean)


58
# File 'lib/sup/account.rb', line 58

def  email; !(email).nil? end

#user_accountsObject



29
# File 'lib/sup/account.rb', line 29

def user_accounts; @accounts.keys; end

#user_emailsObject



30
# File 'lib/sup/account.rb', line 30

def user_emails; @email_map.keys.select { |e| String === e }; end