todo-void 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,5 @@
1
1
  class StatusChangesInteractor
2
+ class StatusChangesInteractor::NoTodoWithIdError < StandardError ; end
2
3
  class ConflictingIdsError < StandardError
3
4
  attr_reader :conflicting_todos
4
5
 
@@ -20,11 +21,14 @@ class StatusChangesInteractor
20
21
  def change_todo_status(hash, status)
21
22
  todos = @list.find(hash).to_array
22
23
 
23
- if todos.length > 1
24
- raise ConflictingIdsError.new(todos)
25
- elsif todos.length == 1
24
+ case todos.length
25
+ when 0
26
+ raise StatusChangesInteractor::NoTodoWithIdError
27
+ when 1
26
28
  todos[0].status = status
27
29
  @store.update(todos[0])
30
+ else
31
+ raise ConflictingIdsError.new(todos)
28
32
  end
29
33
  end
30
34
  end
data/lib/todo_void.rb CHANGED
@@ -17,7 +17,7 @@ class TodoVoid
17
17
  elsif flag?('-s')
18
18
  change_status(:started)
19
19
  elsif flag?('--help')
20
- @output = "Help:\nt 'Mowing the lawn' in order to create a todo\n-f ID to finish a todo\n-d ID to delete a todo"
20
+ @output = read_help
21
21
  elsif @args[0]
22
22
  TodoInteractor.new.add_todo(@args[0])
23
23
  else
@@ -36,9 +36,16 @@ class TodoVoid
36
36
  @args[1]
37
37
  end
38
38
 
39
+ def read_help
40
+ help_template = File.join(File.dirname(__FILE__), '../templates/help')
41
+ File.read(help_template)
42
+ end
43
+
39
44
  def change_status(status)
40
45
  begin
41
46
  StatusChangesInteractor.new.change_status(hash, status)
47
+ rescue StatusChangesInteractor::NoTodoWithIdError
48
+ @output += "There is no todo with matching id"
42
49
  rescue StatusChangesInteractor::ConflictingIdsError => e
43
50
  @output += "Conflicting part of an id provided please be more specific:\n"
44
51
  @output += TodoListView.render(e.conflicting_todos)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: todo-void
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: