Class: Redwood::AccountManager
- Inherits:
-
Object
- Object
- Redwood::AccountManager
- Includes:
- Singleton
- Defined in:
- lib/sup/account.rb
Instance Attribute Summary (collapse)
-
- (Object) default_account
Returns the value of attribute default_account.
Instance Method Summary (collapse)
- - (Object) account_for(email)
-
- (Object) add_account(hash, default = false)
must be called first with the default account.
-
- (AccountManager) initialize(accounts)
constructor
A new instance of AccountManager.
- - (Boolean) is_account?(p)
- - (Boolean) is_account_email?(email)
- - (Object) user_accounts
- - (Object) user_emails
Constructor Details
- (AccountManager) initialize(accounts)
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 add_account accounts[:default], true accounts.each { |k, v| add_account v, false unless k == :default } self.class.i_am_the_instance self end |
Instance Attribute Details
- (Object) default_account
Returns the value of attribute default_account
18 19 20 |
# File 'lib/sup/account.rb', line 18 def default_account @default_account end |
Instance Method Details
- (Object) account_for(email)
64 65 66 67 68 69 70 |
# File 'lib/sup/account.rb', line 64 def account_for email if(a = @email_map[email]) a else @regexen.argfind { |re, a| re =~ email && a } end end |
- (Object) add_account(hash, default = false)
must be called first with the default account. fills in missing values from the default account.
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 add_account 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 |
- (Boolean) is_account?(p)
62 |
# File 'lib/sup/account.rb', line 62 def is_account? p; is_account_email? p.email end |
- (Boolean) is_account_email?(email)
63 |
# File 'lib/sup/account.rb', line 63 def is_account_email? email; !account_for(email).nil? end |
- (Object) user_accounts
32 |
# File 'lib/sup/account.rb', line 32 def user_accounts; @accounts.keys; end |
- (Object) user_emails
33 |
# File 'lib/sup/account.rb', line 33 def user_emails; @email_map.keys.select { |e| String === e }; end |