toodoo 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cdf7e2c1053ffae8bc81afd40ef1823c94eb262c
4
+ data.tar.gz: cc6a302e50a324c930b3f72c4ace7ab515ea63c4
5
+ SHA512:
6
+ metadata.gz: d81ba287986105774a005bd860166360c5589368a22348905d5d68b8425f8bc3fd74bcab26d071e78880626b4b32dc10abd603b2ded6e6128a0e7660932df296
7
+ data.tar.gz: 8f8c44993c79373d26ec418621a200ffd2bb620e60a5b89a09026d5086bfc3a654176aa76565bc63c1bdf2578210e8d66ccb57ec930fc5009b85641cfd200e6f
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format d
3
+ --require spec_helper
@@ -0,0 +1,4 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
3
+ Exclude:
4
+ - 'spec/spec_helper.rb'
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+ ruby '2.3.1'
5
+
6
+ gemspec
@@ -0,0 +1,57 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ toodoo (0.1.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.3.0)
10
+ coderay (1.1.1)
11
+ diff-lcs (1.3)
12
+ method_source (0.8.2)
13
+ parser (2.3.1.2)
14
+ ast (~> 2.2)
15
+ powerpack (0.1.1)
16
+ pry (0.10.4)
17
+ coderay (~> 1.1.0)
18
+ method_source (~> 0.8.1)
19
+ slop (~> 3.4)
20
+ rainbow (2.1.0)
21
+ rspec (3.6.0)
22
+ rspec-core (~> 3.6.0)
23
+ rspec-expectations (~> 3.6.0)
24
+ rspec-mocks (~> 3.6.0)
25
+ rspec-core (3.6.0)
26
+ rspec-support (~> 3.6.0)
27
+ rspec-expectations (3.6.0)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.6.0)
30
+ rspec-mocks (3.6.0)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.6.0)
33
+ rspec-support (3.6.0)
34
+ rubocop (0.39.0)
35
+ parser (>= 2.3.0.7, < 3.0)
36
+ powerpack (~> 0.1)
37
+ rainbow (>= 1.99.1, < 3.0)
38
+ ruby-progressbar (~> 1.7)
39
+ unicode-display_width (~> 1.0, >= 1.0.1)
40
+ ruby-progressbar (1.8.1)
41
+ slop (3.6.0)
42
+ unicode-display_width (1.1.0)
43
+
44
+ PLATFORMS
45
+ ruby
46
+
47
+ DEPENDENCIES
48
+ pry
49
+ rspec
50
+ rubocop
51
+ toodoo!
52
+
53
+ RUBY VERSION
54
+ ruby 2.3.1p112
55
+
56
+ BUNDLED WITH
57
+ 1.15.3
data/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ License
2
+ -------
3
+
4
+ (The MIT License)
5
+
6
+ Copyright (c) 2017 Anton Witkowski
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in all
16
+ copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ SOFTWARE.
@@ -0,0 +1,30 @@
1
+ ## TooDoo
2
+
3
+ command line todo list
4
+
5
+ ```
6
+ gem install toodoo
7
+ ```
8
+
9
+ usage:
10
+
11
+ ```bash
12
+ td add 'to do something' # add a task
13
+ td + 'to do something' # same
14
+ td done 'to do something' # finish a task
15
+ td ! 'to do something' # same
16
+ td remove 'to do something' # remove a task
17
+ td - 'to do something' # same
18
+ td list # list queued tasks
19
+ td . # same
20
+ td # same
21
+ td history # list all done tasks
22
+ td clear # clear all lists
23
+
24
+ ```
25
+
26
+ to implement:
27
+ - zsh autocompletion
28
+ - colors
29
+ - tagging
30
+ - settings(database file)
data/bin/td ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'toodoo'
5
+ TooDoo::Application.new.run!
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+ require 'dbm'
3
+
4
+ # TooDoo is a command line todo-list
5
+ module TooDoo
6
+ VERSION = '0.1.1'
7
+
8
+ require 'toodoo/commands/base'
9
+ require 'toodoo/commands/simple'
10
+ require 'toodoo/commands/list'
11
+ require 'toodoo/commands/done'
12
+ require 'toodoo/commands/add'
13
+ require 'toodoo/commands/remove'
14
+ require 'toodoo/commands/history'
15
+ require 'toodoo/commands/help'
16
+ require 'toodoo/commands/clear'
17
+
18
+ require 'toodoo/commands'
19
+ require 'toodoo/task'
20
+ require 'toodoo/store'
21
+ require 'toodoo/arguments'
22
+ require 'toodoo/application'
23
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TooDoo
4
+ # Application is the entry point for the app
5
+ # it takes arguments and passes them to a command
6
+ # to spin up the corresponding logic
7
+ class Application
8
+ attr_reader :args, :command
9
+
10
+ def initialize(args = Arguments.new)
11
+ @args = args
12
+ @command = recognize_command
13
+ end
14
+
15
+ def run!
16
+ command.new(@args.argument).run!
17
+ end
18
+
19
+ private
20
+
21
+ def recognize_command
22
+ Commands::COMMANDS.fetch \
23
+ @args.command.to_sym, Commands::Help
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TooDoo
4
+ # Arguments is intended to handle passed args
5
+ # and transform it into command name and its arguments
6
+ # I dont want to use OptionParser!
7
+ class Arguments
8
+ attr_reader :command, :argument
9
+
10
+ def initialize(args_array = ARGV)
11
+ @args_array = Array(args_array)
12
+ @command = recognize_command
13
+ @argument = recognize_arguments
14
+ end
15
+
16
+ private
17
+
18
+ def recognize_command
19
+ @args_array.shift || :command_missing
20
+ end
21
+
22
+ def recognize_arguments
23
+ @args_array
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TooDoo
4
+ # Commands is a pack of availalble command logics
5
+ # command entities reprsent their logic and an output
6
+ module Commands
7
+ COMMANDS = {
8
+ list: List,
9
+ add: Add,
10
+ done: Done,
11
+ remove: Remove,
12
+ history: History,
13
+ help: Help,
14
+ clear: Clear,
15
+ command_missing: List,
16
+
17
+ l: List,
18
+ a: Add,
19
+ d: Done,
20
+ r: Remove,
21
+ h: History,
22
+
23
+ :+ => Add,
24
+ :- => Remove,
25
+ :'!' => Done,
26
+ :'.' => List
27
+ }.freeze
28
+ end
29
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pry'
4
+
5
+ module TooDoo
6
+ module Commands
7
+ # add a new task
8
+ # usage: td add <body>
9
+ class Add < Base
10
+ def description
11
+ <<~END
12
+ add a new task
13
+ usage: td add <task>
14
+ END
15
+ end
16
+
17
+ def perform!
18
+ return puts(description) if args.empty?
19
+
20
+ task = Task.new(args.join(' '))
21
+ store.save(task)
22
+ puts build_message(task)
23
+ end
24
+
25
+ private
26
+
27
+ def build_message(task)
28
+ "created - #{task.body}"
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TooDoo
4
+ module Commands
5
+ # Base class represents template for command entity
6
+ # it provides common logic for all commands
7
+ class Base
8
+ attr_reader :args, :store
9
+
10
+ def initialize(args, store = Store)
11
+ @args = args
12
+ @store = store.new
13
+ end
14
+
15
+ def description
16
+ ''
17
+ end
18
+
19
+ def run!
20
+ return puts description if args.empty?
21
+ perform!
22
+ end
23
+
24
+ def perform!
25
+ raise NotImplementedError
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TooDoo
4
+ module Commands
5
+ # clear task lists
6
+ # usage: td clear
7
+ class Clear < Base
8
+ def description
9
+ <<~END
10
+ clear task lists
11
+ usage: td clear
12
+ END
13
+ end
14
+
15
+ def message
16
+ 'lists are empty'
17
+ end
18
+
19
+ def run!
20
+ store.remove_all
21
+ puts message
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TooDoo
4
+ module Commands
5
+ # mark task as done
6
+ # usage: td done <task>
7
+ class Done < Base
8
+ def description
9
+ <<~END
10
+ mark task as done
11
+ usage: td done <task>
12
+ END
13
+ end
14
+
15
+ def perform!
16
+ return puts(description) if args.empty?
17
+
18
+ result = store.find(args.join(' '))
19
+ unless result.nil?
20
+ result.done!
21
+ store.save(result)
22
+ end
23
+
24
+ puts build_message(result)
25
+ end
26
+
27
+ private
28
+
29
+ def build_message(task)
30
+ return 'there is no such task' if task.nil?
31
+ "done - #{task.body}"
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TooDoo
4
+ module Commands
5
+ # list available commands
6
+ # usage: td help
7
+ class Help < Base
8
+ def description
9
+ <<~END
10
+ list available commands
11
+ usage: td help
12
+ END
13
+ end
14
+
15
+ def run!
16
+ perform!
17
+ end
18
+
19
+ def perform!
20
+ puts build_message
21
+ end
22
+
23
+ private
24
+
25
+ def build_message
26
+ <<~END
27
+ usage:
28
+
29
+ help - list available commands
30
+ add <body> - add a new task
31
+ done <body> - mark task as done
32
+ remove <body> - remove a task
33
+ list - list tasks
34
+ history - list done tasks
35
+ clear - clear task lists
36
+ END
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TooDoo
4
+ module Commands
5
+ # list done tasks
6
+ # usage: td history
7
+ class History < Simple
8
+ def description
9
+ <<~END
10
+ list done tasks
11
+ usage: td history
12
+ END
13
+ end
14
+
15
+ private
16
+
17
+ def find_tasks
18
+ store.done
19
+ end
20
+
21
+ def empty_list_message
22
+ 'you have no done tasks yet'
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TooDoo
4
+ module Commands
5
+ # list tasks
6
+ # usage: td list
7
+ class List < Simple
8
+ def description
9
+ <<~END
10
+ list tasks
11
+ usage: td list
12
+ END
13
+ end
14
+
15
+ private
16
+
17
+ def find_tasks
18
+ store.undone
19
+ end
20
+
21
+ def empty_list_message
22
+ 'you have no tasks yet'
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TooDoo
4
+ module Commands
5
+ # remove a task
6
+ # usage: td remove <body>
7
+ class Remove < Base
8
+ def description
9
+ <<~END
10
+ remove a task
11
+ usage: td remove <body>
12
+ END
13
+ end
14
+
15
+ def perform!
16
+ return puts(description) if args.empty?
17
+
18
+ result = store.remove(args.join(' '))
19
+ puts build_message(result)
20
+ end
21
+
22
+ private
23
+
24
+ def build_message(task)
25
+ return 'there is no such task' if task.nil?
26
+ "deleted - #{task.body}"
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TooDoo
4
+ module Commands
5
+ # list your tasks
6
+ # usage: td list
7
+ class Simple < Base
8
+ def run!
9
+ perform!
10
+ end
11
+
12
+ def perform!
13
+ tasks = find_tasks
14
+ @message = build_message(tasks)
15
+ puts @message
16
+ end
17
+
18
+ private
19
+
20
+ def find_tasks
21
+ raise NotImplementedError
22
+ end
23
+
24
+ def empty_list_message
25
+ raise NotImplementedError
26
+ end
27
+
28
+ def build_message(tasks)
29
+ return empty_list_message if tasks.empty?
30
+
31
+ tasks.inject('') do |put, task|
32
+ put + " - #{task.body}\n" unless task.nil?
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TooDoo
4
+ # Store is intended to build connection with db
5
+ # and provide api for the application
6
+ # it saves database file into user's home directory
7
+ # /home/user/.toodoo.db by default
8
+ class Store
9
+ DATABASE_PATH = File.expand_path('~/.toodoo.db')
10
+
11
+ attr_reader :path, :adapter
12
+
13
+ def initialize(db_file_path = DATABASE_PATH, adapter = DBM)
14
+ @path = db_file_path
15
+ @adapter = adapter
16
+ end
17
+
18
+ def all
19
+ connection do |db|
20
+ db.values.each_with_object([]) do |marsh_task, tasks|
21
+ tasks << restore(marsh_task)
22
+ end
23
+ end
24
+ end
25
+
26
+ def undone
27
+ all.reject(&:done?)
28
+ end
29
+
30
+ def done
31
+ all.select(&:done?)
32
+ end
33
+
34
+ def find(body)
35
+ connection do |db|
36
+ result = db[body]
37
+ restore(db[body]) unless result.nil?
38
+ end
39
+ end
40
+
41
+ def save(task)
42
+ raise ArgumentError unless task.is_a?(Task)
43
+
44
+ connection do |db|
45
+ db[task.body] = dump(task)
46
+ end
47
+
48
+ task
49
+ end
50
+
51
+ def remove(body)
52
+ connection do |db|
53
+ result = db.delete(body)
54
+ restore(result) unless result.nil?
55
+ end
56
+ end
57
+
58
+ def remove_all
59
+ connection(&:clear)
60
+ end
61
+
62
+ private
63
+
64
+ def dump(task)
65
+ Marshal.dump(task)
66
+ end
67
+
68
+ def restore(string)
69
+ Marshal.restore(string)
70
+ end
71
+
72
+ def connection
73
+ connection = adapter.new(path)
74
+ result = yield(connection)
75
+ connection.close
76
+
77
+ result
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TooDoo
4
+ # Task is the base model of the app
5
+ # it's a presenter of stored data
6
+ class Task
7
+ attr_reader :body, :status
8
+
9
+ CREATED_STATUS = :created
10
+ DONE_STATUS = :done
11
+
12
+ def initialize(body, status = CREATED_STATUS)
13
+ @body = body
14
+ @status = status
15
+ end
16
+
17
+ def done?
18
+ @status == DONE_STATUS
19
+ end
20
+
21
+ def done!
22
+ @status = DONE_STATUS
23
+ end
24
+
25
+ def ==(other)
26
+ body == other.body && status == other.status
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,103 @@
1
+ require 'toodoo'
2
+ require 'fileutils'
3
+
4
+ # This file was generated by the `rspec --init` command. Conventionally, all
5
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
6
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
7
+ # this file to always be loaded, without a need to explicitly require it in any
8
+ # files.
9
+ #
10
+ # Given that it is always loaded, you are encouraged to keep this file as
11
+ # light-weight as possible. Requiring heavyweight dependencies from this file
12
+ # will add to the boot time of your test suite on EVERY test run, even for an
13
+ # individual file that may not need all of that loaded. Instead, consider making
14
+ # a separate helper file that requires the additional dependencies and performs
15
+ # the additional setup, and require it from the spec files that actually need
16
+ # it.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
44
+ # have no way to turn it off -- the option exists only for backwards
45
+ # compatibility in RSpec 3). It causes shared context metadata to be
46
+ # inherited by the metadata hash of host groups and examples, rather than
47
+ # triggering implicit auto-inclusion in groups with matching metadata.
48
+ config.shared_context_metadata_behavior = :apply_to_host_groups
49
+
50
+ # The settings below are suggested to provide a good initial experience
51
+ # with RSpec, but feel free to customize to your heart's content.
52
+ =begin
53
+ # This allows you to limit a spec run to individual examples or groups
54
+ # you care about by tagging them with `:focus` metadata. When nothing
55
+ # is tagged with `:focus`, all examples get run. RSpec also provides
56
+ # aliases for `it`, `describe`, and `context` that include `:focus`
57
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
58
+ config.filter_run_when_matching :focus
59
+
60
+ # Allows RSpec to persist some state between runs in order to support
61
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
62
+ # you configure your source control system to ignore this file.
63
+ config.example_status_persistence_file_path = "spec/examples.txt"
64
+
65
+ # Limits the available syntax to the non-monkey patched syntax that is
66
+ # recommended. For more details, see:
67
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
68
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
69
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
70
+ config.disable_monkey_patching!
71
+
72
+ # This setting enables warnings. It's recommended, but in some cases may
73
+ # be too noisy due to issues in dependencies.
74
+ config.warnings = true
75
+
76
+ # Many RSpec users commonly either run the entire suite or an individual
77
+ # file, and it's useful to allow more verbose output when running an
78
+ # individual spec file.
79
+ if config.files_to_run.one?
80
+ # Use the documentation formatter for detailed output,
81
+ # unless a formatter has already been configured
82
+ # (e.g. via a command-line flag).
83
+ config.default_formatter = "doc"
84
+ end
85
+
86
+ # Print the 10 slowest examples and example groups at the
87
+ # end of the spec run, to help surface which specs are running
88
+ # particularly slow.
89
+ config.profile_examples = 10
90
+
91
+ # Run specs in random order to surface order dependencies. If you find an
92
+ # order dependency and want to debug it, you can fix the order by providing
93
+ # the seed, which is printed after each run.
94
+ # --seed 1234
95
+ config.order = :random
96
+
97
+ # Seed global randomization in this process using the `--seed` CLI option.
98
+ # Setting this allows you to use `--seed` to deterministically reproduce
99
+ # test failures related to randomization by passing the same `--seed` value
100
+ # as the one that triggered the failure.
101
+ Kernel.srand config.seed
102
+ =end
103
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe TooDoo::Arguments do
4
+ subject { described_class.new(args) }
5
+ let(:command) { 'add' }
6
+ let(:argument) { 'task' }
7
+ let(:args) { [] }
8
+
9
+ context 'when command and argument passed' do
10
+ let(:second_argument) { 'argument' }
11
+ let(:args) { [command, argument, second_argument] }
12
+
13
+ describe '#command' do
14
+ it { expect(subject.command).to eq(command) }
15
+ end
16
+
17
+ describe '#argument' do
18
+ it { expect(subject.argument).to eq([argument, second_argument]) }
19
+ end
20
+ end
21
+
22
+ context 'when only command passed' do
23
+ let(:args) { [command] }
24
+
25
+ describe '#command' do
26
+ it { expect(subject.command).to eq(command) }
27
+ end
28
+
29
+ describe '#argument' do
30
+ it { expect(subject.argument).to be_empty }
31
+ end
32
+ end
33
+
34
+ context 'when nothing passed' do
35
+ let(:args) { [] }
36
+
37
+ describe '#command' do
38
+ it { expect(subject.command).to eq(:command_missing) }
39
+ end
40
+
41
+ describe '#argument' do
42
+ it { expect(subject.argument).to be_empty }
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,108 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe TooDoo::Store do
4
+ temp_path = 'tmp'
5
+ db_file_name = 'test.db'
6
+ full_db_path = "#{temp_path}/#{db_file_name}"
7
+
8
+ before(:all) do
9
+ puts "---------- db file will be placed to #{full_db_path} -----------"
10
+ FileUtils.mkdir(temp_path)
11
+ FileUtils.touch(full_db_path)
12
+ end
13
+
14
+ after(:each) do
15
+ GDBM.open(full_db_path, &:clear)
16
+ end
17
+
18
+ after(:all) do
19
+ puts "---------- removing db file from #{full_db_path} ---------------"
20
+ FileUtils.rm_rf(Dir['tmp'])
21
+ end
22
+
23
+ let(:body) { 'something here' }
24
+ let(:first_task) { TooDoo::Task.new(body) }
25
+ let(:second_task) { TooDoo::Task.new('something else') }
26
+
27
+ subject { described_class.new(full_db_path) }
28
+
29
+ describe '#all' do
30
+ context 'when some entries exist' do
31
+ before do
32
+ subject.save first_task
33
+ subject.save second_task
34
+ end
35
+
36
+ it { expect(subject.all).to eq([first_task, second_task]) }
37
+ end
38
+
39
+ context 'when db is empty' do
40
+ it { expect(subject.all).to eq([]) }
41
+ end
42
+ end
43
+
44
+ describe '#undone' do
45
+ let(:second_task) do
46
+ TooDoo::Task.new('something else', TooDoo::Task::DONE_STATUS)
47
+ end
48
+
49
+ before do
50
+ subject.save first_task
51
+ subject.save second_task
52
+ end
53
+
54
+ it { expect(subject.undone).to eq([first_task]) }
55
+ end
56
+
57
+ describe '#done' do
58
+ let(:second_task) do
59
+ TooDoo::Task.new('something else', TooDoo::Task::DONE_STATUS)
60
+ end
61
+
62
+ before do
63
+ subject.save first_task
64
+ subject.save second_task
65
+ end
66
+
67
+ it { expect(subject.done).to eq([second_task]) }
68
+ end
69
+
70
+ describe '#find' do
71
+ before do
72
+ subject.save first_task
73
+ subject.save second_task
74
+ end
75
+
76
+ it { expect(subject.find(body)).to eq(first_task) }
77
+ end
78
+
79
+ describe '#save' do
80
+ it do
81
+ expect { subject.save(first_task) }
82
+ .to change { subject.all.length }.from(0).to(1)
83
+ end
84
+ end
85
+
86
+ describe '#remove' do
87
+ before do
88
+ subject.save first_task
89
+ end
90
+
91
+ it do
92
+ expect { subject.remove(body) }
93
+ .to change { subject.all.length }.from(1).to(0)
94
+ end
95
+ end
96
+
97
+ describe '#remove_all' do
98
+ before do
99
+ subject.save first_task
100
+ subject.save second_task
101
+ end
102
+
103
+ it do
104
+ expect { subject.remove_all }
105
+ .to change { subject.all.length }.from(2).to(0)
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe TooDoo::Task do
4
+ let(:body) { 'something here' }
5
+
6
+ subject { described_class.new(body) }
7
+
8
+ describe '#done?' do
9
+ it { expect(subject.status).to eq(:created) }
10
+
11
+ context 'when task is done' do
12
+ before do
13
+ subject.done!
14
+ end
15
+
16
+ it { expect(subject.done?).to be_truthy }
17
+ end
18
+
19
+ context 'when task isnt done' do
20
+ it { expect(subject.done?).to be_falsey }
21
+ end
22
+ end
23
+
24
+ describe '#done!' do
25
+ it do
26
+ expect { subject.done! }
27
+ .to change { subject.status }.from(:created).to(:done)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'toodoo'
5
+ spec.version = '0.1.1'
6
+ spec.summary = 'petite command line todo list'
7
+ spec.description = 'minimalistic todo utility for your command line'
8
+ spec.authors = ['Anton Witkowski']
9
+ spec.email = 'antnwtkwsk@gmail.com'
10
+ spec.homepage = 'https://github.com/witkwski/toodoo'
11
+ spec.license = 'MIT'
12
+
13
+ spec.files = `git ls-files`.strip.split("\n")
14
+ spec.require_paths = ['lib']
15
+ spec.executables << 'td'
16
+
17
+ spec.required_ruby_version = '>= 2.3.0'
18
+
19
+ spec.add_development_dependency 'rspec', '>= 3.6.0'
20
+ spec.add_development_dependency 'pry', '>= 0.10.4'
21
+ spec.add_development_dependency 'rubocop', '0.39.0'
22
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: toodoo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Anton Witkowski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.6.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.6.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.10.4
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.10.4
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.39.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.39.0
55
+ description: minimalistic todo utility for your command line
56
+ email: antnwtkwsk@gmail.com
57
+ executables:
58
+ - td
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".rspec"
63
+ - ".rubocop.yml"
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - LICENSE
67
+ - README.md
68
+ - bin/td
69
+ - lib/toodoo.rb
70
+ - lib/toodoo/application.rb
71
+ - lib/toodoo/arguments.rb
72
+ - lib/toodoo/commands.rb
73
+ - lib/toodoo/commands/add.rb
74
+ - lib/toodoo/commands/base.rb
75
+ - lib/toodoo/commands/clear.rb
76
+ - lib/toodoo/commands/done.rb
77
+ - lib/toodoo/commands/help.rb
78
+ - lib/toodoo/commands/history.rb
79
+ - lib/toodoo/commands/list.rb
80
+ - lib/toodoo/commands/remove.rb
81
+ - lib/toodoo/commands/simple.rb
82
+ - lib/toodoo/store.rb
83
+ - lib/toodoo/task.rb
84
+ - spec/spec_helper.rb
85
+ - spec/toodoo/arguments_spec.rb
86
+ - spec/toodoo/store_spec.rb
87
+ - spec/toodoo/task_spec.rb
88
+ - toodoo.gemspec
89
+ homepage: https://github.com/witkwski/toodoo
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: 2.3.0
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.5.1
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: petite command line todo list
113
+ test_files: []