posto 0.3.2 → 0.3.3

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.
@@ -3,69 +3,56 @@ require 'posto/file'
3
3
 
4
4
  module Posto
5
5
  class Application
6
- def initialize(arguments)
7
- @arguments = arguments
8
- @list_utility = List
9
- @io = STDOUT
10
- @file = Posto::File.new(@arguments.filename)
11
- end
12
-
13
- def list(todos)
14
- todos
15
- end
6
+ attr_accessor :todos, :io, :file
7
+ alias :list :todos
16
8
 
17
- def run(todos)
18
- @io.puts send(@arguments.command, todos, *@arguments.params)
19
- end
20
-
21
- def sort(todos)
22
- @file.write @list_utility.sort(todos)
23
- end
24
-
25
- def resort(todos)
26
- @file.write @list_utility.resort(todos)
9
+ def initialize(arguments, todos, options = {})
10
+ @io = options[:io] || STDOUT
11
+ @list_utility = options[:list_utility] || List
12
+ @file = options[:file] || Posto::File.new(arguments.filename)
13
+ @arguments = arguments
14
+ @todos = todos
27
15
  end
28
16
 
29
- def unsort(todos, n = 1)
30
- @file.write @list_utility.unsort(todos, n.to_i)
31
- lookup_todo(todos, n)
17
+ def run
18
+ @io.puts send(@arguments.command, *@arguments.params)
32
19
  end
33
20
 
34
- def done(todos, n = 1)
35
- @file.write @list_utility.done(todos, n.to_i)
36
- lookup_todo(todos, n)
21
+ [:sort, :resort].each do |method|
22
+ define_method method do
23
+ @file.write(@list_utility.send(method, todos))
24
+ end
37
25
  end
38
26
 
39
- def top(todos, n = 1)
40
- @file.write @list_utility.top(todos, n.to_i)
41
- lookup_todo(todos, n)
27
+ [:unsort, :done, :delete, :do, :top, :quick].each do |method|
28
+ define_method method do |n = 1|
29
+ @file.write @list_utility.send(method, todos, n.to_i)
30
+ @list_utility.lookup(todos, n)
31
+ end
42
32
  end
43
33
 
44
- def quick(todos, n = 1)
45
- @file.write @list_utility.quick(todos, n.to_i)
46
- lookup_todo(todos, n)
34
+ def add(todo)
35
+ @file.write @todos = @list_utility.add(todos, todo)
36
+ todo
47
37
  end
48
38
 
49
- def add(todos, todo)
50
- @file.write @list_utility.add(todos, todo)
51
- todo
39
+ def start(todo)
40
+ add(todo)
41
+ sort
42
+ @file.commit_alone("[posto] scheduled '#{todo}'")
52
43
  end
53
44
 
54
- def commit(todos, n = 1)
55
- @file.commit(done(todos, n))
45
+ def commit(n = 1)
46
+ @file.commit("[posto] finished '#{done(n)}'")
56
47
  end
57
48
 
58
- def init(todos)
49
+ def init
59
50
  @file.touch
60
51
  nil
61
52
  end
62
53
 
63
- def lookup_todo(todos, n)
64
- Posto::Todo.hide_markdown(todos[n.to_i - 1])
65
- end
66
-
67
54
  def method_missing(symbol, *args)
68
- STDERR.puts "Unsupported operation '#{symbol} #{args.join " "}'"
55
+ STDERR.puts "Unsupported operation '#{symbol} #{args.join "\n"}'"
69
56
  end
70
57
  end
71
58
  end
data/lib/posto/file.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'posto/template'
1
+ require 'posto/list'
2
2
 
3
3
  module Posto
4
4
  class File
@@ -7,7 +7,7 @@ module Posto
7
7
  end
8
8
 
9
9
  def write(todos)
10
- IO.write(@filename, Template.todo_list(todos))
10
+ IO.write(@filename, template(todos))
11
11
  end
12
12
 
13
13
  def commit(msg)
@@ -15,16 +15,24 @@ module Posto
15
15
  `git commit -m "#{msg}"`
16
16
  end
17
17
 
18
+ def commit_alone(msg)
19
+ `git commit -m "#{msg}" #@filename`
20
+ end
21
+
18
22
  def touch
19
23
  `touch #@filename`
20
24
  end
21
25
 
22
- def lines
26
+ def todos
23
27
  if ::File.exists? @filename
24
- IO.read(@filename).split("\n")
28
+ List.choose_todo_lines(IO.read(@filename).split("\n"))
25
29
  else
26
30
  []
27
31
  end
28
32
  end
33
+
34
+ def template(todos)
35
+ "todo\n----\n\n#{todos.join("\n")}\n"
36
+ end
29
37
  end
30
38
  end
@@ -0,0 +1,19 @@
1
+ require 'posto/todo'
2
+
3
+ module Posto
4
+ class HumanComparison
5
+ def self.template(x, y)
6
+ "\n================\n\n1. #{x}\n\n2. #{y}\n\n" +
7
+ "which one is more important? (1, 2 or just hit enter if you don't care): "
8
+ end
9
+
10
+ def self.ask_human(x, y)
11
+ while true do
12
+ response = ask(template(Todo.hide_markdown(x), Todo.hide_markdown(y))).to_i
13
+ return 0 if response == 0
14
+ return -1 if response == 1
15
+ return 1 if response == 2
16
+ end
17
+ end
18
+ end
19
+ end
data/lib/posto/list.rb CHANGED
@@ -1,19 +1,21 @@
1
1
  require 'posto/todo'
2
2
  require 'posto/monkeypatch_array'
3
+ require 'posto/human_comparison'
3
4
 
4
5
  module Posto
5
6
  class List
6
7
  class << self
7
8
  def number_todos(todos)
8
- todos.each_with_index.map { |todo, i| Todo.number(todo, i + 1) }
9
+ todos.each_with_index.map { |todo, i| Posto::Todo.number(todo, i + 1) }
9
10
  end
10
11
 
11
12
  def choose_todo_lines(lines)
12
- lines.select { |line| Todo.todo?(line) }
13
+ todos, backlog = lines.slice_before(/^backlog$/).to_a
14
+ todos.select { |todo| Todo.todo?(todo) }
13
15
  end
14
16
 
15
17
  def sort(todos)
16
- number_todos(todos.sort { |x, y| Todo.compare_sorted_todos(x, y) or Todo.ask_human_to_compare(x, y) })
18
+ number_todos(todos.sort { |x, y| Todo.compare_sorted_todos(x, y) or HumanComparison.ask_human(x, y) })
17
19
  end
18
20
 
19
21
  def starred_group(todos)
@@ -27,6 +29,7 @@ module Posto
27
29
  def done(todos, n)
28
30
  unsort(todos, n)[0..-2]
29
31
  end
32
+ alias :delete :done
30
33
 
31
34
  def unsort(todos, n)
32
35
  numbered_group(todos.reject_at(n - 1)) + starred_group(todos.reject_at(n - 1)) + [Todo.star(todos[n - 1])]
@@ -51,6 +54,11 @@ module Posto
51
54
  array = [todos[n - 1]]
52
55
  number_todos(array + numbered_group) + starred_group
53
56
  end
57
+ alias :do :top
58
+
59
+ def lookup(todos, n)
60
+ Posto::Todo.hide_markdown(todos[n.to_i - 1])
61
+ end
54
62
  end
55
63
  end
56
64
  end
data/lib/posto/todo.rb CHANGED
@@ -1,19 +1,8 @@
1
- require 'posto/template'
2
-
3
1
  module Posto
4
2
  class Todo
5
3
  class << self
6
4
  MD_LIST_TODO = /^(\*|\d+\.) /
7
5
 
8
- def ask_human_to_compare(x, y)
9
- while true do
10
- response = ask(Template.human_comparison(hide_markdown(x), hide_markdown(y))).to_i
11
- return 0 if response == 0
12
- return -1 if response == 1
13
- return 1 if response == 2
14
- end
15
- end
16
-
17
6
  def compare_sorted_todos(x, y)
18
7
  x = x.to_i
19
8
  y = y.to_i
data/lib/posto.rb CHANGED
@@ -8,8 +8,8 @@ module Posto
8
8
  class << self
9
9
  def main(args)
10
10
  arguments = Arguments.new(args)
11
- todos = List.choose_todo_lines(File.new(arguments.filename).lines)
12
- Application.new(arguments).run(todos)
11
+ todos = Posto::File.new(arguments.filename).todos
12
+ Application.new(arguments, todos).run
13
13
  end
14
14
  end
15
15
  end
@@ -0,0 +1,48 @@
1
+ require 'test_helper'
2
+ require 'posto/application'
3
+ require 'grasshopper'
4
+
5
+ describe Posto::Application do
6
+ describe "#list" do
7
+ it "shows todo items" do
8
+ args = Stub.like(:command => "list", :params => [])
9
+ app = Posto::Application.new(args, ["* foo", "* bar"], :io => Mock.new)
10
+
11
+ app.run
12
+
13
+ Mock.verify(app.io).puts(["* foo", "* bar"])
14
+ end
15
+ end
16
+
17
+ [:sort, :resort].each do |method|
18
+ describe "##{method}" do
19
+ it "calls #{method} on the list_utility given" do
20
+ args = Stub.like(:command => method, :params => [])
21
+ file = Mock.new
22
+ list_utility = Mock.new
23
+
24
+ app = Posto::Application.new(args, [], :file => file, :list_utility => list_utility, :io => Stub.new)
25
+ app.run
26
+
27
+ Mock.verify(list_utility).send(method, [])
28
+ Mock.verify(file).write(nil)
29
+ end
30
+ end
31
+ end
32
+
33
+ [:unsort, :done, :delete, :do, :top, :quick].each do |method|
34
+ describe "##{method}" do
35
+ it "calls #{method} on the list_utility given" do
36
+ args = Stub.like(:command => method, :params => ["4"])
37
+ list_utility = Mock.new
38
+
39
+ file = Mock.new
40
+ app = Posto::Application.new(args, [], :list_utility => list_utility, :file => file, :io => Stub.new)
41
+ app.run
42
+
43
+ Mock.verify(list_utility).send(method, [], 4)
44
+ Mock.verify(file).write(nil)
45
+ end
46
+ end
47
+ end
48
+ end
data/test/list_test.rb CHANGED
@@ -9,7 +9,10 @@ class ListTest < MiniTest::Unit::TestCase
9
9
 
10
10
  def test_choose_todo_lines
11
11
  assert_equal(["99. bottles", "* unsorted todo"],
12
- Posto::List.choose_todo_lines(["TODO", "======", "99. bottles", "* unsorted todo", "END", ""]))
12
+ Posto::List.choose_todo_lines(["TODO", "----", "99. bottles", "* unsorted todo", ""]))
13
+ assert_equal(["99. bottles", "* unsorted todo"],
14
+ Posto::List.choose_todo_lines(["TODO", "----", "99. bottles", "* unsorted todo", "",
15
+ "backlog", "-------","","* nada", "* none"]))
13
16
  end
14
17
 
15
18
  def test_starred_group
@@ -3,7 +3,6 @@ require 'posto/monkeypatch_array'
3
3
 
4
4
  class MonkeypatchArrayTest < MiniTest::Unit::TestCase
5
5
  def test_reject_at_returns_a_modified_array_doesnt_modify_original
6
- remainder = [1, 2, 3].freeze.reject_at(2)
7
- assert_equal([1, 2], remainder)
6
+ assert_equal([1, 2], [1, 2, 3].freeze.reject_at(2))
8
7
  end
9
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: posto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-13 00:00:00.000000000 Z
12
+ date: 2012-09-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -55,16 +55,17 @@ files:
55
55
  - LICENSE.txt
56
56
  - bin/posto
57
57
  - lib/posto/monkeypatch_array.rb
58
- - lib/posto/template.rb
59
58
  - lib/posto/application.rb
60
59
  - lib/posto/list.rb
61
60
  - lib/posto/todo.rb
62
61
  - lib/posto/file.rb
63
62
  - lib/posto/arguments.rb
63
+ - lib/posto/human_comparison.rb
64
64
  - lib/posto.rb
65
65
  - test/list_test.rb
66
66
  - test/arguments_test.rb
67
67
  - test/test_helper.rb
68
+ - test/application_test.rb
68
69
  - test/monkeypatch_array_test.rb
69
70
  - test/todo_test.rb
70
71
  homepage: http://github.com/mattraibert/posto
@@ -82,7 +83,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
82
83
  version: '0'
83
84
  segments:
84
85
  - 0
85
- hash: -2327369408914751837
86
+ hash: 3530876056305707581
86
87
  required_rubygems_version: !ruby/object:Gem::Requirement
87
88
  none: false
88
89
  requirements:
@@ -99,5 +100,6 @@ test_files:
99
100
  - test/list_test.rb
100
101
  - test/arguments_test.rb
101
102
  - test/test_helper.rb
103
+ - test/application_test.rb
102
104
  - test/monkeypatch_array_test.rb
103
105
  - test/todo_test.rb
@@ -1,11 +0,0 @@
1
- module Posto
2
- module Template
3
- def self.todo_list(todos)
4
- "todo\n----\n\n#{todos.join("\n")}\n"
5
- end
6
-
7
- def self.human_comparison(x, y)
8
- "\n================\n\n1. #{x}\n\n2. #{y}\n\nwhich one is more important? (1, 2 or just hit enter if you don't care): "
9
- end
10
- end
11
- end