todo-void 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/t +4 -0
- data/interactors/status_changes_interactor.rb +23 -0
- data/interactors/todo_interactor.rb +29 -0
- data/lib/todo.rb +17 -0
- data/lib/todo_list.rb +22 -0
- data/lib/todo_list_view.rb +30 -0
- data/lib/todo_store.rb +37 -0
- data/lib/todo_view.rb +17 -0
- data/lib/todo_void.rb +26 -0
- metadata +70 -0
data/bin/t
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
class StatusChangesInteractor
|
|
2
|
+
def initialize(store = TodoStore.new)
|
|
3
|
+
@store = store
|
|
4
|
+
@list = @store.read
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def finish_todo(hash)
|
|
8
|
+
change_todo_status(hash, :finished)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def start_todo(hash)
|
|
12
|
+
change_todo_status(hash, :started)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
def change_todo_status(hash, status)
|
|
17
|
+
todo = @list.find(hash)
|
|
18
|
+
@list.remove(todo)
|
|
19
|
+
todo.status = status
|
|
20
|
+
@list.add(todo)
|
|
21
|
+
@store.save(@list)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require_relative '../lib/todo_store'
|
|
2
|
+
|
|
3
|
+
class TodoInteractor
|
|
4
|
+
def initialize(store = TodoStore.new)
|
|
5
|
+
@store = store
|
|
6
|
+
@list = @store.read
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def add_todo(description)
|
|
10
|
+
@list.add(Todo.new(description))
|
|
11
|
+
save_list
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def delete_todo(hash)
|
|
15
|
+
@list.remove(hash)
|
|
16
|
+
save_list
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def list_all
|
|
20
|
+
todos = []
|
|
21
|
+
@list.todo.each do |id, todo| todos << todo end
|
|
22
|
+
todos
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
def save_list
|
|
27
|
+
@store.save(@list)
|
|
28
|
+
end
|
|
29
|
+
end
|
data/lib/todo.rb
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'openssl'
|
|
2
|
+
|
|
3
|
+
class Todo
|
|
4
|
+
attr_reader :description
|
|
5
|
+
attr_accessor :status
|
|
6
|
+
|
|
7
|
+
def initialize(description)
|
|
8
|
+
@description = description
|
|
9
|
+
@status = :pending
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def id
|
|
13
|
+
description_hash = OpenSSL::Digest::SHA1.new(@description)
|
|
14
|
+
description_hash = description_hash.hexdigest
|
|
15
|
+
description_hash.slice(0..5)
|
|
16
|
+
end
|
|
17
|
+
end
|
data/lib/todo_list.rb
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
class TodoList
|
|
2
|
+
attr_reader :todo
|
|
3
|
+
|
|
4
|
+
def initialize
|
|
5
|
+
@todo = {}
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def add(todo)
|
|
9
|
+
@todo.store(todo.id, todo)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def find(search)
|
|
13
|
+
@todo.each do |id, todo|
|
|
14
|
+
return todo if /^#{search}/.match id
|
|
15
|
+
end
|
|
16
|
+
nil
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def remove(hash)
|
|
20
|
+
@todo.delete(hash)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require_relative "../lib/todo_view"
|
|
2
|
+
|
|
3
|
+
class TodoListView
|
|
4
|
+
def initialize(todos)
|
|
5
|
+
@todos = todos
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def render
|
|
9
|
+
@output = ""
|
|
10
|
+
render_todo_by_status(:started)
|
|
11
|
+
render_todo_by_status(:pending)
|
|
12
|
+
render_todo_by_status(:finished)
|
|
13
|
+
@output
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
def render_todo_by_status(status)
|
|
18
|
+
todos_by_status(status).each { |todo| render_todo(todo) }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def todos_by_status(status)
|
|
22
|
+
@todos.reject {|todo| todo.status != status}
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def render_todo(todos)
|
|
26
|
+
@output += TodoView.new(todos).render
|
|
27
|
+
@output += "\n"
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
data/lib/todo_store.rb
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require_relative "./todo_list"
|
|
2
|
+
require_relative './todo'
|
|
3
|
+
require 'fileutils'
|
|
4
|
+
|
|
5
|
+
class TodoStore
|
|
6
|
+
def read
|
|
7
|
+
todo_list = TodoList.new
|
|
8
|
+
|
|
9
|
+
FileUtils.touch(todo_file)
|
|
10
|
+
file_content = File.readlines(todo_file)
|
|
11
|
+
|
|
12
|
+
file_content.each do |line|
|
|
13
|
+
line = line.gsub("\n", "")
|
|
14
|
+
status, description = line.split "||"
|
|
15
|
+
todo = Todo.new(description)
|
|
16
|
+
todo.status = status.to_sym
|
|
17
|
+
todo_list.add todo
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
todo_list
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def save(list)
|
|
24
|
+
seriaized_todos = ""
|
|
25
|
+
todos = list.todo
|
|
26
|
+
todos.each do |id, todo|
|
|
27
|
+
seriaized_todos += "#{todo.status}||#{todo.description}\n"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
File.write(todo_file, seriaized_todos)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
private
|
|
34
|
+
def todo_file
|
|
35
|
+
Dir.home + '/.todos'
|
|
36
|
+
end
|
|
37
|
+
end
|
data/lib/todo_view.rb
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'rainbow'
|
|
2
|
+
|
|
3
|
+
class TodoView
|
|
4
|
+
def initialize(todo)
|
|
5
|
+
@todo = todo
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def render
|
|
9
|
+
if @todo.status == :finished
|
|
10
|
+
"#{@todo.id} #{@todo.description}".foreground(:black)
|
|
11
|
+
elsif @todo.status == :started
|
|
12
|
+
"#{@todo.id.foreground(:green)} #{@todo.description}"
|
|
13
|
+
else
|
|
14
|
+
"#{@todo.id.foreground(:yellow)} #{@todo.description}"
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
data/lib/todo_void.rb
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require_relative '../interactors/todo_interactor.rb'
|
|
2
|
+
require_relative '../interactors/status_changes_interactor.rb'
|
|
3
|
+
|
|
4
|
+
class TodoVoid
|
|
5
|
+
def self.execute(args)
|
|
6
|
+
output = ""
|
|
7
|
+
|
|
8
|
+
if args[0] == "-d"
|
|
9
|
+
TodoInteractor.new.delete_todo(args[1])
|
|
10
|
+
elsif args[0] == "-f"
|
|
11
|
+
StatusChangesInteractor.new.finish_todo(args[1])
|
|
12
|
+
elsif args[0] == "-s"
|
|
13
|
+
StatusChangesInteractor.new.start_todo(args[1])
|
|
14
|
+
elsif args[0] == "--help"
|
|
15
|
+
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"
|
|
16
|
+
elsif args[0]
|
|
17
|
+
TodoInteractor.new.add_todo(args[0])
|
|
18
|
+
else
|
|
19
|
+
require_relative './todo_list_view.rb'
|
|
20
|
+
todos = TodoInteractor.new.list_all
|
|
21
|
+
view = TodoListView.new(todos)
|
|
22
|
+
output = view.render
|
|
23
|
+
end
|
|
24
|
+
output
|
|
25
|
+
end
|
|
26
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: todo-void
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Robert Curth
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2011-07-21 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: rainbow
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '0'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ! '>='
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '0'
|
|
30
|
+
description: A simple app to manage todos
|
|
31
|
+
email: robert@rocu.de
|
|
32
|
+
executables:
|
|
33
|
+
- t
|
|
34
|
+
extensions: []
|
|
35
|
+
extra_rdoc_files: []
|
|
36
|
+
files:
|
|
37
|
+
- lib/todo.rb
|
|
38
|
+
- lib/todo_list.rb
|
|
39
|
+
- lib/todo_list_view.rb
|
|
40
|
+
- lib/todo_store.rb
|
|
41
|
+
- lib/todo_view.rb
|
|
42
|
+
- lib/todo_void.rb
|
|
43
|
+
- bin/t
|
|
44
|
+
- interactors/status_changes_interactor.rb
|
|
45
|
+
- interactors/todo_interactor.rb
|
|
46
|
+
homepage: http://rubygems.org/gems/todo-void
|
|
47
|
+
licenses: []
|
|
48
|
+
post_install_message:
|
|
49
|
+
rdoc_options: []
|
|
50
|
+
require_paths:
|
|
51
|
+
- lib
|
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
53
|
+
none: false
|
|
54
|
+
requirements:
|
|
55
|
+
- - ! '>='
|
|
56
|
+
- !ruby/object:Gem::Version
|
|
57
|
+
version: '0'
|
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
|
+
none: false
|
|
60
|
+
requirements:
|
|
61
|
+
- - ! '>='
|
|
62
|
+
- !ruby/object:Gem::Version
|
|
63
|
+
version: '0'
|
|
64
|
+
requirements: []
|
|
65
|
+
rubyforge_project:
|
|
66
|
+
rubygems_version: 1.8.24
|
|
67
|
+
signing_key:
|
|
68
|
+
specification_version: 3
|
|
69
|
+
summary: Todo-Void!
|
|
70
|
+
test_files: []
|