Class: Cli::Base
Instance Attribute Summary
Attributes included from Client
#config
Instance Method Summary
collapse
Methods included from Ui
#puts_padded
Methods included from Lists
#ask_for_list, #inbox_first, #list_title_for, #lists, #lists_list, #show_list_list, #show_task_list
Methods included from Client
#client, #config_file, #load_config, #save_config
Instance Method Details
#add(todo = nil) ⇒ Object
34
35
36
37
38
39
40
41
42
|
# File 'lib/cli/base.rb', line 34
def add(todo = nil)
todo = ask("What to do?") unless todo
list_id = options[:list]
max_position = client.tasks.find_all{ |t| t.list_id == list_id }
.sort_by { |t| t.position }[0]
client.tasks.create(title: todo, list_id: list_id, position: max_position.position-0.1)
end
|
#all ⇒ Object
21
22
23
24
25
26
27
28
29
|
# File 'lib/cli/base.rb', line 21
def all
task_lists = client.tasks.find_all { |t| t.completed_at.nil? }
if options[:list]
task_lists = task_lists.find_all { |t| t.list_id == options[:list] }
end
show_list_list(task_lists.group_by { |t| t.list_id })
end
|
#all_lists ⇒ Object
58
59
60
|
# File 'lib/cli/base.rb', line 58
def all_lists
lists_list
end
|
#completed(todo_id) ⇒ Object
45
46
47
48
49
|
# File 'lib/cli/base.rb', line 45
def completed(todo_id)
task = client.tasks.find { |t| t.id == todo_id }
task.completed_at = Time.now.to_s
task.save
end
|
#delete(todo_id) ⇒ Object
52
53
54
55
|
# File 'lib/cli/base.rb', line 52
def delete(todo_id)
task = client.tasks.find { |t| t.id == todo_id }
task.destroy
end
|
#setup ⇒ Object
11
12
13
14
15
16
|
# File 'lib/cli/base.rb', line 11
def setup
load_config
config[:username] = ask("Username: ")
config[:password] = ask("Password: ")
wirte_config
end
|