class PF::QiniuProfile
Attributes
accounts[RW]
default_account[RW]
Public Class Methods
new(parent)
click to toggle source
# File lib/pf/profile/profile.rb, line 62 def initialize(parent) @parent = parent @accounts = [] end
Public Instance Methods
account(name=nil)
click to toggle source
# File lib/pf/profile/profile.rb, line 71 def account(name=nil) name = @default_account if name.nil? @accounts.find { |account| account.name == name} end
add_account(new_account, default: true)
click to toggle source
# File lib/pf/profile/profile.rb, line 105 def add_account(new_account, default: true) updated = true account = account(new_account.name) if account.nil? @accounts.push(new_account) else if account.equal? new_account updated = false else # remove_account(new_account.name) @accounts.delete_if{|a| a.name == new_account} @accounts.unshift(new_account) end end if default @default_account = new_account.name end update_default updated end
exist_account?(name)
click to toggle source
# File lib/pf/profile/profile.rb, line 67 def exist_account?(name) !account(name).nil? end
remove_account(name)
click to toggle source
# File lib/pf/profile/profile.rb, line 76 def remove_account(name) @accounts.delete_if{|account| account.name == name} update_default end
save()
click to toggle source
# File lib/pf/profile/profile.rb, line 129 def save @parent.save end
update_default(name: nil)
click to toggle source
# File lib/pf/profile/profile.rb, line 81 def update_default(name: nil) if name.nil? if @default_account.nil? unless @accounts.empty? @default_account = @accounts.first.name end else if @accounts.empty? @default_account = nil else if account.nil? @default_account = @accounts.first.name end end end else if exist_account? name @default_account = name else update_default end end end