rubdo 0.2.6 → 0.3.0

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/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --colour
2
+ --format progress
3
+ --fail-fast
data/README.md CHANGED
@@ -2,47 +2,69 @@
2
2
 
3
3
  Why does todo applications need to be so complicated?
4
4
 
5
- ## Installation
5
+ ## Usage
6
6
 
7
- Add this line to your application's Gemfile:
7
+ Since version `0.3.0`, `rubdo` can handle several TODO files with
8
+ environment variables. So you can change TODO file by setting:
8
9
 
9
- gem 'rubdo'
10
+ ```bash
11
+ $ export TODO_FILE="PATH/TO/TODO_FILE" # i.e ~/.tasks/Work.yml
12
+ ```
10
13
 
11
- And then execute:
14
+ When you are done with your other TODO file, just simply kill the
15
+ environment variable or reload the shell
12
16
 
13
- $ bundle
17
+ Here are the available commands for `rubdo`
14
18
 
15
- Or install it yourself as:
19
+ ```bash
20
+ Commands for rubdo:
21
+ -------------------
22
+ add/a [task description] - Add a new task. If the description is empty, $EDITOR is opened
23
+ list/ls - Lists all tasks
24
+ done/d [task id] - Complete a task
25
+ edit/e [task id] - Opens up $EDITOR to edit the task description
26
+ remove/rm [task id] - Deletes the specific task, same as done
27
+ help - Prints out this information
28
+ ```
29
+
30
+ `rubdo` createas _~/.tasks_ where it holds the YAML file with the todos inside.
31
+ If you want to keep your todos synced accross your machines, make a symlink to say
32
+ directory inside of _~/Dropbox_
16
33
 
17
- $ gem install rubdo
34
+ ```bash
35
+ $ ln -s ~/Dropbox/tasks/ ~/.tasks
36
+ ```
18
37
 
19
- ## Usage
38
+ Make sure to save your todos first!
20
39
 
21
- Here are the available commands for `rubdo`
40
+ A tip is to alias `rubdo` to `t` for easier typing
41
+ for `bash` and `zsh`
22
42
 
23
- Commands for rubdo:
24
- ------------------
25
- add/a [task description] - Add a new task. If the description is empty, $EDITOR is opened
26
- list/ls - Lists all tasks
27
- done/d [task id] - Complete a task
28
- edit/e [task id] - Opens up $EDITOR to edit the task description
29
- remove/rm [task id] - Deletes the specific task, same as done
30
- help - Prints out this information
43
+ ```bash
44
+ alias t="rubdo"
45
+ ```
31
46
 
32
- `rubdo` createas _~/.tasks_ where it holds the YAML files with the todos inside.
33
- If you want to keep your todos synced accross your machines, make a symlink to say
34
- a directory inside of _~/Dropbox_
47
+ and add that to your _{bash, zsh}rc_
35
48
 
36
- $ ln -s ~/Dropbox/tasks/ ~/.tasks
49
+ ## Installation
37
50
 
38
- Make sure to save your todos first!
51
+ Add this line to your application's Gemfile:
39
52
 
40
- A tip is to alias `rubdo` to `t` for easier typing
41
- for `bash` and `zsh`
53
+ ```bash
54
+ gem 'rubdo'
55
+ ```
56
+
57
+ And then execute:
42
58
 
43
- alias t="rubdo"
59
+ ```bash
60
+ $ bundle
61
+ ```
62
+
63
+ Or install it yourself as:
44
64
 
45
- and add that to your _{bash, zsh}rc_
65
+ ```bash
66
+ $ gem install rubdo
67
+ ```
46
68
 
47
69
  ## Contributing
48
70
 
data/Rakefile CHANGED
@@ -1,9 +1,11 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
3
4
 
5
+ RSpec::Core::RakeTask.new(:spec)
4
6
  task :default => :spec
5
- desc 'Run all tests' do
6
- task :spec do
7
- `rspec --color --format nested spec/*`
8
- end
7
+
8
+ task :console do
9
+ sh "pry -I lib -r rubdo"
9
10
  end
11
+ task c: :console
data/bin/rubdo CHANGED
@@ -6,7 +6,7 @@ require 'abbrev'
6
6
  cli = Rubdo::CLI.new
7
7
  methods = Rubdo::CLI.public_instance_methods(false).map(&:to_s).abbrev
8
8
  cli.list if ARGV[0].nil?
9
- begin
9
+ begin
10
10
  cli.send methods[ARGV[0]] unless ARGV[0].nil?
11
11
  rescue
12
12
  puts "cowardly refuses" unless methods[ARGV[0]]
@@ -1,4 +1,3 @@
1
- require "rubdo/version"
2
- require 'rubdo/cli'
3
- require 'rubdo/item'
4
- require 'rubdo/list'
1
+ Dir[File.dirname(__FILE__) + '/rubdo/**/*.rb'].each do |file|
2
+ require file
3
+ end
@@ -3,7 +3,7 @@ require 'tempfile'
3
3
  module Rubdo
4
4
  class CLI
5
5
  def initialize
6
- todos = List.read(File.expand_path('~/.tasks/Todo.yml'))
6
+ todos = List.read(todo_file)
7
7
  @list = List.new(todos)
8
8
  @id = ARGV[1].to_i - 1
9
9
  end
@@ -12,14 +12,7 @@ module Rubdo
12
12
  if ARGV[1]
13
13
  @list.add ARGV[1]
14
14
  else
15
- tmp_file = Tempfile.new('new_task')
16
- system("$EDITOR #{tmp_file.path}")
17
- unless File.read(tmp_file.path).empty?
18
- @list.add File.read(tmp_file).chomp
19
- tmp_file.delete
20
- else
21
- puts "aborted due to empty file"
22
- end
15
+ Tempfile.open('new_task') { |tf| @list.add Rubdo::Editor.add(tf.path) }
23
16
  end
24
17
  save
25
18
  end
@@ -28,20 +21,16 @@ module Rubdo
28
21
  @list.done @id
29
22
  save
30
23
  end
24
+ alias_method :rm, :done
31
25
 
32
26
  def list
33
- @list.to_a.each_with_index { |item, index| puts "#{index + 1}: #{item.description}" }
34
- puts "no tasks" if @list.to_a.empty?
27
+ list_tasks unless @list.to_a.empty?
35
28
  end
29
+ alias_method :ls, :list
36
30
 
37
31
  def edit
38
- abort("not a valid id") if @id == -1 or @id > @list.to_a.length
39
-
40
- tmp_file = Tempfile.new('new_description')
41
- File.open(tmp_file.path, 'w') { |f| f.write(@list.to_a[@id].description) }
42
- system("$EDITOR #{tmp_file.path}")
43
- @list.to_a[@id].description = File.read(tmp_file).chomp
44
- tmp_file.delete
32
+ abort("not a valid id") if @id > @list.to_a.size
33
+ Tempfile.open('new_description') { |tf| task.description = Rubdo::Editor.edit(tf.path, task.description) }
45
34
  save
46
35
  end
47
36
 
@@ -57,13 +46,22 @@ help - Prints out this information
57
46
  HELP
58
47
  end
59
48
 
60
- alias_method :ls, :list
61
- alias_method :rm, :done
62
-
63
49
  private
64
50
 
65
51
  def save
66
52
  @list.write
67
53
  end
54
+
55
+ def list_tasks
56
+ @list.to_a.each_with_index { |item, index| puts "#{index + 1}: #{item.description}" }
57
+ end
58
+
59
+ def task
60
+ @list.to_a[@id]
61
+ end
62
+
63
+ def todo_file
64
+ @todo_file ||= '~/.tasks/Todo.yml'
65
+ end
68
66
  end
69
67
  end
@@ -0,0 +1,29 @@
1
+ module Rubdo
2
+ class Editor
3
+
4
+ def self.edit(file, description)
5
+ write_description(file, description)
6
+ open_with_editor(file)
7
+ read_description(file)
8
+ end
9
+
10
+ def self.add(file)
11
+ open_with_editor(file)
12
+ read_description(file)
13
+ end
14
+
15
+ private
16
+
17
+ def self.open_with_editor(file)
18
+ system "$EDITOR #{file}"
19
+ end
20
+
21
+ def self.write_description(file, description)
22
+ File.open(file, 'w') { |f| f.write(description) }
23
+ end
24
+
25
+ def self.read_description(file)
26
+ File.read(file).chomp
27
+ end
28
+ end
29
+ end
@@ -7,7 +7,7 @@ module Rubdo
7
7
  end
8
8
 
9
9
  def to_s
10
- self.description
10
+ description
11
11
  end
12
12
  end
13
13
  end
@@ -1,45 +1,42 @@
1
1
  require 'time'
2
2
  require 'yaml'
3
- require 'fileutils'
4
3
 
5
4
  module Rubdo
6
5
  class List
7
- attr_accessor :items, :storage
8
6
 
9
- def self.read(file)
10
- todos = YAML.load_file(file) if File.exists? file
11
- todos ||=[]
7
+ attr_reader :items, :todo_file
12
8
 
13
- todos
9
+ def self.read(file = nil)
10
+ todo_file = File.expand_path(file)
11
+ items = File.exists?(todo_file) ? YAML.load_file(todo_file) : []
12
+ { items: items, todo_file: todo_file }
14
13
  end
15
14
 
16
- def initialize(todos)
17
- @items = todos
18
- @storage = File.expand_path('~/.tasks/Todo.yml')
19
- FileUtils.mkdir_p File.dirname @storage
15
+ def initialize(options)
16
+ @items = options.fetch(:items) { [] }
17
+ @todo_file = options.fetch(:todo_file) { File.expand_path("~/.tasks/Todo.yml") }
20
18
  end
21
19
 
22
20
  def add(description)
23
- @items << Item.new(description)
21
+ items << Item.new(description)
24
22
  end
23
+ alias_method :<<, :add
25
24
 
26
25
  def done(id)
27
- @items.delete_at id
26
+ items.delete_at id
28
27
  end
29
28
 
30
29
  def edit(id)
31
- @items[id]
30
+ items[id]
32
31
  end
33
32
 
34
33
  def write
35
- File.open(self.storage, 'w') { |todos| todos.write(@items.to_yaml) }
34
+ File.open(todo_file, 'w') { |f| f.write(items.to_yaml) }
36
35
  end
36
+ alias_method :save, :write
37
37
 
38
38
  def to_a
39
- self.items
39
+ items
40
40
  end
41
-
42
- alias_method :<<, :add
43
- alias_method :save, :write
44
41
  end
45
42
  end
@@ -1,3 +1,3 @@
1
1
  module Rubdo
2
- VERSION = "0.2.6"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -0,0 +1,11 @@
1
+ require_relative '../lib/rubdo/item'
2
+
3
+ describe Rubdo::Item do
4
+ let(:item) { Rubdo::Item.new 'New todo item' }
5
+
6
+ describe '#new' do
7
+ it 'assigns a description to the item' do
8
+ item.description.should eq 'New todo item'
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,55 @@
1
+ require_relative '../lib/rubdo/list'
2
+ require_relative '../lib/rubdo/item'
3
+
4
+ describe Rubdo::List do
5
+ let(:list) { Rubdo::List.new items: [], todo_file: '/tmp/todo.yml' }
6
+
7
+ describe '#new' do
8
+ let(:empty_list) { Rubdo::List.new({})}
9
+
10
+ context 'with parameters' do
11
+ it 'sets `items` and `todo_file`' do
12
+ list.items.should eq []
13
+ list.todo_file.should eq '/tmp/todo.yml'
14
+ end
15
+ end
16
+
17
+ context 'without parameters' do
18
+ it 'fallback for `items` and `todo_file`' do
19
+ empty_list.items.should eq []
20
+ empty_list.todo_file.should eq File.expand_path('~/.tasks/Todo.yml')
21
+ end
22
+ end
23
+ end
24
+
25
+ describe '#add' do
26
+ it 'adds 3 items to the list' do
27
+ list.add 'Buy milk'
28
+ list.add 'Buy beer'
29
+ list.add 'But peanuts'
30
+
31
+ list.to_a.size.should eq 3
32
+ end
33
+ end
34
+
35
+ describe '#done' do
36
+ it 'deletes an item from the list' do
37
+ list.add 'Watch TV'
38
+ list.add 'Walk the dog'
39
+ list.to_a.size.should eq 2
40
+ list.done 0
41
+
42
+ list.to_a.size.should eq 1
43
+ end
44
+ end
45
+
46
+ describe '#edit' do
47
+ it 'changes the description of a certain task' do
48
+ list.add "I can't go out, I'm sik"
49
+ list.edit(0).description = "I can't go out, I'm sick"
50
+
51
+ list.to_a[0].description.should eq "I can't go out, I'm sick"
52
+ list.to_a.size.should eq 1
53
+ end
54
+ end
55
+ end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubdo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
5
4
  prerelease:
5
+ version: 0.3.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Teo Ljungberg
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-22 00:00:00.000000000 Z
12
+ date: 2013-01-19 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: My take on the todo-applications
15
15
  email:
@@ -21,6 +21,7 @@ extra_rdoc_files: []
21
21
  files:
22
22
  - .gitignore
23
23
  - .rake_tasks
24
+ - .rspec
24
25
  - Gemfile
25
26
  - LICENSE
26
27
  - README.md
@@ -28,11 +29,13 @@ files:
28
29
  - bin/rubdo
29
30
  - lib/rubdo.rb
30
31
  - lib/rubdo/cli.rb
32
+ - lib/rubdo/editor.rb
31
33
  - lib/rubdo/item.rb
32
34
  - lib/rubdo/list.rb
33
35
  - lib/rubdo/version.rb
34
36
  - rubdo.gemspec
35
- - spec/rubdo_tests.rb
37
+ - spec/item_spec.rb
38
+ - spec/list_spec.rb
36
39
  homepage: http://github.com/metamorfos/rubdo
37
40
  licenses: []
38
41
  post_install_message:
@@ -40,17 +43,17 @@ rdoc_options: []
40
43
  require_paths:
41
44
  - lib
42
45
  required_ruby_version: !ruby/object:Gem::Requirement
43
- none: false
44
46
  requirements:
45
47
  - - ! '>='
46
48
  - !ruby/object:Gem::Version
47
49
  version: '0'
48
- required_rubygems_version: !ruby/object:Gem::Requirement
49
50
  none: false
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
52
  requirements:
51
53
  - - ! '>='
52
54
  - !ruby/object:Gem::Version
53
55
  version: '0'
56
+ none: false
54
57
  requirements: []
55
58
  rubyforge_project:
56
59
  rubygems_version: 1.8.23
@@ -58,4 +61,5 @@ signing_key:
58
61
  specification_version: 3
59
62
  summary: My take on the todo-applications
60
63
  test_files:
61
- - spec/rubdo_tests.rb
64
+ - spec/item_spec.rb
65
+ - spec/list_spec.rb
@@ -1,55 +0,0 @@
1
- require 'rspec'
2
- require 'rubdo'
3
-
4
- describe Rubdo::Item do
5
- before do
6
- @item = Rubdo::Item.new('New todo item')
7
- end
8
-
9
- describe '#new' do
10
- it 'assigns a text value to rubdo' do
11
- @item.description.should eq('New todo item')
12
- end
13
- end
14
- end
15
-
16
- describe Rubdo::List do
17
- before do
18
- @list = Rubdo::List.new(Rubdo::List.read(File.join(File.dirname(__FILE__), 'test.yml')))
19
- end
20
-
21
- describe '#add' do
22
- it 'adds 3 todo items' do
23
- @list.add('Buy milk')
24
- @list.add('Buy beer')
25
- @list.add('But peanuts')
26
- @list.to_a.size.should eq(3)
27
- end
28
- end
29
-
30
- describe '#done' do
31
- before do
32
- @list = Rubdo::List.new(Rubdo::List.read(File.join(File.dirname(__FILE__), 'test.yml')))
33
- end
34
-
35
- it 'deletes a todo item' do
36
- @list.add('Watch TV')
37
- @list.add('Walk the dog')
38
- @list.done(0).description.should eq('Watch TV')
39
- @list.to_a.size.should eq(1)
40
- end
41
- end
42
-
43
- describe '#edit' do
44
- before do
45
- @list = Rubdo::List.new(Rubdo::List.read(File.join(File.dirname(__FILE__), 'test.yml')))
46
- end
47
-
48
- it 'edits a task' do
49
- @list.add("I can't go out, I'm sik")
50
- @list.edit(0).description = "I can't go out, I'm sick"
51
- @list.to_a[0].description.should eq("I can't go out, I'm sick")
52
- @list.to_a.size.should eq(1)
53
- end
54
- end
55
- end