Class: Morale::Commands::Project
- Inherits:
-
Object
- Object
- Morale::Commands::Project
show all
- Extended by:
- IO
- Defined in:
- lib/morale/commands/project.rb
Class Method Summary
collapse
Methods included from IO
ask, ask_for_secret, ask_for_secret_on_windows, echo_off, echo_on, say
Class Method Details
.list(change = false) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/morale/commands/project.rb', line 10
def list(change=false)
begin
projects = Morale::Command.client.projects
if !projects.nil?
projects.sort{|a,b| a['project']['name'] <=> b['project']['name']}.each_with_index do |record, i|
puts "#{i += 1}. #{record['project']['name']}#{' *' if Morale::Account.project(false) == record['project']['id'].to_s}"
end
if change
say "Choose a project: "
index = ask
project = projects[index.to_i - 1]
if project.nil?
say "Invalid project."
end
Morale::Account.project = project['project']['id'] unless project.nil?
end
else
say "There were no projects found."
end
rescue Morale::Client::Unauthorized
say "Authentication failure"
Morale::Commands::Authorization.login
retry if Morale::Authorization.retry_login?
rescue Morale::Client::NotFound
say "Communication failure"
end
end
|
.select(id) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/morale/commands/project.rb', line 40
def select(id)
begin
projects = Morale::Command.client.projects
if !projects.nil?
project = projects[id.to_i - 1]
if project.nil?
say "Invalid project."
end
Morale::Account.project = project['project']['id'] unless project.nil?
else
say "There were no projects found."
end
rescue Morale::Client::Unauthorized
say "Authentication failure"
Morale::Commands::Authorization.login
retry if Morale::Authorization.retry_login?
rescue Morale::Client::NotFound
say "Communication failure"
end
end
|