class Redwood::AccountManager
Attributes
default_account[RW]
Public Class Methods
new(accounts)
click to toggle source
# File lib/sup/account.rb, line 32 def initialize accounts @email_map = {} @accounts = {} @regexen = {} @default_account = nil add_account accounts[:default], true accounts.each { |k, v| add_account v, false unless k == :default } end
Public Instance Methods
account_for(email)
click to toggle source
# File lib/sup/account.rb, line 77 def account_for email if(a = @email_map[email]) a else @regexen.argfind { |re, a| re =~ email && a } end end
add_account(hash, default=false)
click to toggle source
must be called first with the default account. fills in missing values from the default account.
# File lib/sup/account.rb, line 47 def add_account hash, default=false raise ArgumentError, "no email specified for account" unless hash[:email] unless default [:name, :sendmail, :signature, :gpgkey].each { |k| hash[k] ||= @default_account.send(k) } end hash[:alternates] ||= [] fail "alternative emails are not an array: #{hash[:alternates]}" unless hash[:alternates].kind_of? Array [:name, :signature].each { |x| hash[x] ? hash[x].fix_encoding! : nil } 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
full_address_for(email)
click to toggle source
# File lib/sup/account.rb, line 84 def full_address_for email a = account_for email Person.full_address a.name, email end
is_account?(p;)
click to toggle source
# File lib/sup/account.rb, line 75 def is_account? p; is_account_email? p.email end
is_account_email?(email;)
click to toggle source
# File lib/sup/account.rb, line 76 def is_account_email? email; !account_for(email).nil? end
user_accounts()
click to toggle source
# File lib/sup/account.rb, line 42 def user_accounts; @accounts.keys; end
user_emails()
click to toggle source
# File lib/sup/account.rb, line 43 def user_emails; @email_map.keys.select { |e| String === e }; end