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



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sup/account.rb', line 20

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

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

  self.class.i_am_the_instance self
end

Instance Attribute Details

#default_accountObject

Returns the value of attribute default_account



18
19
20
# File 'lib/sup/account.rb', line 18

def 
  @default_account
end

Instance Method Details

#account_for(email) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/sup/account.rb', line 64

def  email
  if(a = @email_map[email])
    a
  else
    @regexen.argfind { |re, a| re =~ email && a }
  end
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)


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/sup/account.rb', line 37

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] ||= []

  a = Account.new hash
  @accounts[a] = true

  if default
    raise ArgumentError, "multiple default accounts" if @default_account
    @default_account = a
  end

  ([hash[:email]] + hash[:alternates]).each do |email|
    next if @email_map.member? email
    @email_map[email] = a
  end

  hash[:regexen].each do |re|
    @regexen[Regexp.new(re)] = a
  end if hash[:regexen]
end

#is_account?(p) ⇒ Boolean

Returns:

  • (Boolean)


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

def is_account? p;  p.email end

#is_account_email?(email) ⇒ Boolean

Returns:

  • (Boolean)


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

def  email; !(email).nil? end

#user_accountsObject



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

def user_accounts; @accounts.keys; end

#user_emailsObject



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

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