Class: EYCli::Controller::Accounts

Inherits:
Object
  • Object
show all
Defined in:
lib/ey_cli/controllers/accounts.rb

Instance Method Summary collapse

Instance Method Details

#fetch_account(name = nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/ey_cli/controllers/accounts.rb', line 4

def (name = nil)
  accounts = fetch_accounts
  if name
    EYCli::Model::Account.find_by_name(name, accounts)
  else
    return accounts.first if accounts.empty? || accounts.size == 1

    name = EYCli.term.choose_resource(accounts,
            "I don't know which account you want to use.",
            'Please, select an account:')
    EYCli::Model::Account.find_by_name(name, accounts)
  end
end

#fetch_accountsObject



18
19
20
# File 'lib/ey_cli/controllers/accounts.rb', line 18

def fetch_accounts
  EYCli::Model::Account.all.sort_by {|| .name}
end