Class: Redwood::AccountManager
- Includes:
- Singleton
- Defined in:
- lib/sup/account.rb
Instance Attribute Summary collapse
-
#default_account ⇒ Object
Returns the value of attribute default_account.
Instance Method Summary collapse
- #account_for(email) ⇒ Object
-
#add_account(hash, default = false) ⇒ Object
must be called first with the default account.
-
#initialize(accounts) ⇒ AccountManager
constructor
A new instance of AccountManager.
- #is_account?(p) ⇒ Boolean
- #is_account_email?(email) ⇒ Boolean
- #user_accounts ⇒ Object
- #user_emails ⇒ Object
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 add_account accounts[:default], true accounts.each { |k, v| add_account v unless k == :default } self.class.i_am_the_instance self end |
Instance Attribute Details
#default_account ⇒ Object
Returns the value of attribute default_account.
16 17 18 |
# File 'lib/sup/account.rb', line 16 def default_account @default_account end |
Instance Method Details
#account_for(email) ⇒ Object
57 |
# File 'lib/sup/account.rb', line 57 def account_for 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.
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 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] ||= [] 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
56 |
# File 'lib/sup/account.rb', line 56 def is_account? p; is_account_email? p.email end |
#is_account_email?(email) ⇒ Boolean
58 |
# File 'lib/sup/account.rb', line 58 def is_account_email? email; !account_for(email).nil? end |
#user_accounts ⇒ Object
29 |
# File 'lib/sup/account.rb', line 29 def user_accounts; @accounts.keys; end |
#user_emails ⇒ Object
30 |
# File 'lib/sup/account.rb', line 30 def user_emails; @email_map.keys.select { |e| String === e }; end |