todo_lists 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cc19b5ffc1303b4e97efa499caec33266aba4d1aa1b47afb0b1d3a6735fbdc64
4
+ data.tar.gz: f25c974810a3acbb52c3a2497126f168ab144663da82be665badf6f87436bd29
5
+ SHA512:
6
+ metadata.gz: 3a6466c2dc1347e522fe9d44735eb381c5694a4d9791119d8f0c84ffd4a7a94ff12b465131d2ebc1bf5474c0bfe99dcf2b599eb2967da0d3783d9a73f99ba376
7
+ data.tar.gz: 6899c0bde086b6a9f55451cf0ef1ef9a0f1657f8ab307e877502a683dd5dd8143356684f6c5ecf65d0992594de01b9477d063e3f04ae8e71cb96f2b24b2e23d8
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.gem
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 2.0.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at aurangzaib.danial@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in todo_lists.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,77 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ todo_lists (0.1.0)
5
+ activerecord (~> 5.2)
6
+ sqlite3 (= 1.3.13)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (5.2.3)
12
+ activesupport (= 5.2.3)
13
+ activerecord (5.2.3)
14
+ activemodel (= 5.2.3)
15
+ activesupport (= 5.2.3)
16
+ arel (>= 9.0)
17
+ activesupport (5.2.3)
18
+ concurrent-ruby (~> 1.0, >= 1.0.2)
19
+ i18n (>= 0.7, < 2)
20
+ minitest (~> 5.1)
21
+ tzinfo (~> 1.1)
22
+ arel (9.0.0)
23
+ coderay (1.1.2)
24
+ concurrent-ruby (1.1.5)
25
+ diff-lcs (1.3)
26
+ i18n (1.7.0)
27
+ concurrent-ruby (~> 1.0)
28
+ method_source (0.9.2)
29
+ minitest (5.12.2)
30
+ mustermann (1.0.3)
31
+ pry (0.12.2)
32
+ coderay (~> 1.1.0)
33
+ method_source (~> 0.9.0)
34
+ rack (2.0.7)
35
+ rack-protection (2.0.7)
36
+ rack
37
+ rake (10.5.0)
38
+ rspec (3.8.0)
39
+ rspec-core (~> 3.8.0)
40
+ rspec-expectations (~> 3.8.0)
41
+ rspec-mocks (~> 3.8.0)
42
+ rspec-core (3.8.2)
43
+ rspec-support (~> 3.8.0)
44
+ rspec-expectations (3.8.5)
45
+ diff-lcs (>= 1.2.0, < 2.0)
46
+ rspec-support (~> 3.8.0)
47
+ rspec-mocks (3.8.2)
48
+ diff-lcs (>= 1.2.0, < 2.0)
49
+ rspec-support (~> 3.8.0)
50
+ rspec-support (3.8.3)
51
+ sinatra (2.0.7)
52
+ mustermann (~> 1.0)
53
+ rack (~> 2.0)
54
+ rack-protection (= 2.0.7)
55
+ tilt (~> 2.0)
56
+ sinatra-activerecord (2.0.14)
57
+ activerecord (>= 3.2)
58
+ sinatra (>= 1.0)
59
+ sqlite3 (1.3.13)
60
+ thread_safe (0.3.6)
61
+ tilt (2.0.10)
62
+ tzinfo (1.2.5)
63
+ thread_safe (~> 0.1)
64
+
65
+ PLATFORMS
66
+ ruby
67
+
68
+ DEPENDENCIES
69
+ bundler (~> 2.0)
70
+ pry (~> 0.12.2)
71
+ rake (~> 10.0)
72
+ rspec (~> 3.0)
73
+ sinatra-activerecord (= 2.0.14)
74
+ todo_lists!
75
+
76
+ BUNDLED WITH
77
+ 2.0.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Aurangzaib
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # TodoLists
2
+
3
+ Simple Command Line Application for your every day TodoLists needs, you do not have leave your terminal for your todolists, all the lists are persisted to database, never worry about losing your precious lists.
4
+
5
+ ## Installation
6
+
7
+ Note: You need to have sqlite installed in your computer http://www.sqlite.org
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'todo_lists'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install todo_lists
22
+
23
+ ## Usage
24
+ From your terminal
25
+
26
+ $ todo_lists
27
+
28
+ ## Development
29
+
30
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
31
+
32
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
33
+
34
+ ## Contributing
35
+
36
+ Bug reports and pull requests are welcome on GitHub at https://github.com/aurangzaib_danial/todo_lists. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
41
+
42
+ ## Code of Conduct
43
+
44
+ Everyone interacting in the TodoLists project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/aurangzaib_danial/todo_lists/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ require 'bundler/setup'
5
+
6
+ require 'sqlite3'
7
+ require 'active_record'
8
+
9
+ require_relative 'config/environment'
10
+ require "sinatra/activerecord/rake"
11
+
12
+
13
+ RSpec::Core::RakeTask.new(:spec)
14
+
15
+ task :default => :spec
16
+
17
+ desc 'reset development database'
18
+ task :reset_development do
19
+ system('rm -rf db/schema.rb')
20
+ system('rm -rf db/todo_lists.sqlite')
21
+ system('rake db:migrate')
22
+ end
23
+
24
+ desc 'reset production database'
25
+ task :reset_production do
26
+ system('rm -rf ~/.todo_lists')
27
+ end
data/TODO.md ADDED
@@ -0,0 +1,33 @@
1
+ Make a Todo list manager
2
+
3
+ Simple CRUD Interface (Persisted to Database)
4
+
5
+ Mantra
6
+ 1. Use tests where necessary
7
+ 2. Develop from outside to inside
8
+
9
+ Implement Functionality
10
+
11
+ [X] Setup basic structure
12
+ [X] Setup gem requirements
13
+ [X] Setup database
14
+ [X] Test model associations in console
15
+ [X] Develop basic user interface
16
+ [X] make new todo list with a title
17
+ [X] list all todo lists
18
+ [X] update a list title
19
+ [X] delete a list
20
+ [X] Move all list cli functionality to its own controller
21
+ [X] list a specific list
22
+ [X] After new action, enter the list
23
+ [X] add items to a list
24
+ [X] edit item of a list
25
+ [X] mark an item done of a list
26
+ [X] delete item of a list
27
+ [] Update README
28
+ [] Build gem, install locally and test
29
+ [] Push to rubygems.org
30
+
31
+ Associations
32
+ List has many items
33
+ Item belongs to list
data/bin/console ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "todo_lists"
5
+
6
+ require_relative '../config/environment'
7
+
8
+ def reload
9
+ load 'lib/todo_lists/models/list.rb'
10
+ load 'lib/todo_lists/models/item.rb'
11
+ end
12
+
13
+ ActiveRecord::Base.logger = Logger.new(STDOUT)
14
+
15
+ require 'pry'
16
+
17
+ Pry.start(TodoLists) # start in context of the namespace TodoLists, so I do not have to reference my models like this TodoLists::List but just List
18
+
19
+ # You can add fixtures and/or initialization code here to make experimenting
20
+ # with your gem easier. You can also use a different console, if you like.
21
+
22
+ # (If you use this, don't forget to add pry to your Gemfile!)
23
+ # require "pry"
24
+ # Pry.start
25
+
26
+ # require "irb"
27
+ # IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ # This file is for development purposes
2
+ ActiveRecord::Base.establish_connection(
3
+ database: "db/todo_lists.sqlite",
4
+ adapter: 'sqlite3'
5
+ )
@@ -0,0 +1,7 @@
1
+ class CreateLists < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :lists do |t|
4
+ t.string :title
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ class CreateItems < ActiveRecord::Migration[5.2]
2
+ def change
3
+ create_table :items do |t|
4
+ t.text :content
5
+ t.integer :list_id
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ class AddDoneToItems < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_column :items, :done, :boolean, :default => false
4
+ end
5
+ end
data/db/schema.rb ADDED
@@ -0,0 +1,25 @@
1
+ # This file is auto-generated from the current state of the database. Instead
2
+ # of editing this file, please use the migrations feature of Active Record to
3
+ # incrementally modify your database, and then regenerate this schema definition.
4
+ #
5
+ # Note that this schema.rb definition is the authoritative source for your
6
+ # database schema. If you need to create the application database on another
7
+ # system, you should be using db:schema:load, not running all the migrations
8
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
9
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
10
+ #
11
+ # It's strongly recommended that you check this file into your version control system.
12
+
13
+ ActiveRecord::Schema.define(version: 2019_10_12_023313) do
14
+
15
+ create_table "items", force: :cascade do |t|
16
+ t.text "content"
17
+ t.integer "list_id"
18
+ t.boolean "done", default: false
19
+ end
20
+
21
+ create_table "lists", force: :cascade do |t|
22
+ t.string "title"
23
+ end
24
+
25
+ end
Binary file
data/exe/todo_lists ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # require "bundler/setup" # commment out when publishing
3
+ require "todo_lists"
4
+
5
+
6
+ TodoLists::CLI.new.call
@@ -0,0 +1,114 @@
1
+ class TodoLists::CLI
2
+
3
+ attr_reader :lists_controller, :items_controller
4
+ def initialize
5
+ @lists_controller = TodoLists::ListsController.new
6
+ @items_controller = TodoLists::ItemsController.new
7
+ end
8
+
9
+
10
+ def call
11
+
12
+ if TodoLists::List.count == 0
13
+ lists_controller.index
14
+ lists_controller.new
15
+ @list = TodoLists::List.last
16
+ if @list
17
+ items_menu
18
+ lists_menu
19
+ end
20
+ else
21
+ lists_menu
22
+ end
23
+
24
+ end
25
+
26
+ def lists_menu
27
+
28
+ until lists_controller.last_input == '/exit'
29
+
30
+ if @help_shown
31
+ @help_shown = false
32
+ else
33
+ lists_controller.index
34
+ end
35
+
36
+ puts "\nEnter list number or \'/help\' for more options or type /exit"
37
+
38
+ lists_controller.get_input
39
+
40
+ last_input = lists_controller.last_input.downcase
41
+
42
+ if last_input.to_i > 0
43
+ @list = TodoLists::List.find_by_index(last_input)
44
+ items_menu if @list
45
+
46
+ elsif last_input == '/new'
47
+ last_before_new = TodoLists::List.last
48
+
49
+ lists_controller.new
50
+
51
+ last_after_new = TodoLists::List.last
52
+
53
+ if last_before_new != last_after_new # find out if a list was created in new action or not
54
+ @list = last_after_new
55
+ items_menu
56
+ end
57
+
58
+ elsif last_input.match?(/\/edit\s\d+/)
59
+ lists_controller.edit
60
+
61
+ elsif last_input.match?(/\/delete\s\d+/)
62
+ lists_controller.delete
63
+
64
+ elsif last_input == '/help'
65
+ lists_controller.help
66
+ @help_shown = true
67
+ end
68
+
69
+ end
70
+ end
71
+
72
+ def items_menu
73
+ items_controller.list = @list
74
+
75
+ until items_controller.last_input == '/exit' || items_controller.last_input == '/main'
76
+ if @help_shown
77
+ @help_shown = false
78
+ else
79
+ items_controller.index
80
+ end
81
+
82
+ puts "\nEnter new item or \'/help\' for more options or type /main"
83
+
84
+ items_controller.get_input
85
+ last_input = items_controller.last_input.downcase
86
+
87
+ if last_input.match?(/\/done\s\d+/)
88
+ items_controller.done
89
+
90
+ elsif last_input.match?(/\/edit\s\d+/)
91
+ items_controller.edit
92
+
93
+ elsif last_input.match?(/\/delete\s\d+/)
94
+ items_controller.delete
95
+
96
+ elsif last_input == '/help'
97
+ items_controller.help
98
+ @help_shown = true
99
+
100
+ elsif last_input != '/exit' and last_input != '/main'
101
+ items_controller.new
102
+ end
103
+
104
+ end
105
+
106
+ case items_controller.last_input.downcase
107
+ when '/exit'
108
+ lists_controller.last_input = '/exit' # exit from lists_menu as well
109
+ end
110
+
111
+ items_controller.last_input = nil # reset last_input
112
+ end
113
+
114
+ end
@@ -0,0 +1,73 @@
1
+ class TodoLists::ItemsController
2
+
3
+ attr_accessor :list, :last_input
4
+
5
+ Item = TodoLists::Item
6
+
7
+ def help
8
+ puts "\nOptions available"
9
+ puts '/edit {item_id}'
10
+ puts '/delete {item_id}'
11
+ puts '/done {item_id} (mark item complete)'
12
+ puts '/exit'
13
+ puts
14
+ end
15
+
16
+ def done
17
+ item_index = last_input.split(' ')[1]
18
+ item = Item.find_by_index_and_list_id(index: item_index, list_id: list.id)
19
+ if item
20
+ item.done = true
21
+ item.save
22
+ end
23
+ end
24
+
25
+ def edit
26
+ item_index = last_input.split(' ')[1]
27
+ item = Item.find_by_index_and_list_id(index: item_index, list_id: list.id)
28
+ if item
29
+ print 'Enter new content: '
30
+ get_input
31
+ item.content = last_input
32
+ item.save
33
+ end
34
+ end
35
+
36
+ def delete
37
+ item_index = last_input.split(' ')[1]
38
+ item = Item.find_by_index_and_list_id(index: item_index, list_id: list.id)
39
+ if item
40
+ print 'Are you sure? Enter \'y/n\': '
41
+ get_input
42
+
43
+ if last_input.downcase == 'y'
44
+ item.destroy
45
+ end
46
+
47
+ end
48
+ end
49
+
50
+ def index
51
+ if list.items.count == 0
52
+ puts "\nYou have no items in '#{@list.title.capitalize}'."
53
+ else
54
+ puts "\n---------------#{list.title.capitalize}---------------"
55
+ puts '# item'
56
+ puts '-- -----'
57
+ list.items.reload.each.with_index(1) do |item, index|
58
+ puts "#{index}: #{item.content.capitalize} [#{'X' if item.done?}]"
59
+ end
60
+ end
61
+ end
62
+
63
+ def new
64
+
65
+ item = Item.new(list: list, content: last_input)
66
+
67
+ item.save
68
+ end
69
+
70
+ def get_input
71
+ @last_input = gets.strip
72
+ end
73
+ end
@@ -0,0 +1,69 @@
1
+ class TodoLists::ListsController
2
+
3
+ attr_accessor :last_input
4
+
5
+ List = TodoLists::List
6
+
7
+ def help
8
+ puts "\nOptions available"
9
+ puts '/new (for a new list)'
10
+ puts '/edit {list_number}'
11
+ puts '/delete {list_number}'
12
+ puts
13
+ end
14
+
15
+ def edit
16
+ list_index = last_input.split(' ')[1]
17
+ list = List.find_by_index(list_index)
18
+ if list
19
+ print 'Enter new title: '
20
+ get_input
21
+ list.title = last_input
22
+ list.save
23
+ end
24
+ end
25
+
26
+ def delete
27
+ list_index = last_input.split(' ')[1]
28
+ list = List.find_by_index(list_index)
29
+ if list
30
+ print 'Are you sure? Enter \'y/n\': '
31
+ get_input
32
+
33
+ if last_input.downcase == 'y'
34
+ list.items.destroy_all
35
+ list.destroy
36
+ end
37
+
38
+ end
39
+ end
40
+
41
+ def index
42
+ if List.count == 0
43
+ puts 'You have no TodoList, create one or type \'/exit\''
44
+ else
45
+ puts "\n---------------TodoLists---------------"
46
+ puts '# title'
47
+ puts '-- -----'
48
+ List.all.each.with_index(1) do |list, index|
49
+ puts "#{index}: #{list.title.capitalize}"
50
+ end
51
+ end
52
+ end
53
+
54
+ def new
55
+
56
+ print 'Enter Title: '
57
+ get_input
58
+
59
+ return if last_input == '/exit'
60
+
61
+ list = List.new(title: last_input)
62
+
63
+ list.save
64
+ end
65
+
66
+ def get_input
67
+ @last_input = gets.strip
68
+ end
69
+ end
@@ -0,0 +1,8 @@
1
+ class TodoLists::Item < ActiveRecord::Base
2
+ belongs_to :list
3
+ validates :content, :presence => :true
4
+
5
+ def self.find_by_index_and_list_id(index:, list_id:)
6
+ where(:list_id => list_id)[index.to_i-1]
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ class TodoLists::List < ActiveRecord::Base
2
+ has_many :items
3
+ validates :title, :presence => true
4
+
5
+ def self.find_by_index(index)
6
+ all[index.to_i-1]
7
+ end
8
+ end
@@ -0,0 +1,25 @@
1
+ if !File.exists? "#{Dir.home}/.todo_lists"
2
+
3
+ DB = SQLite3::Database.new "#{Dir.home}/.todo_lists"
4
+
5
+ items_sql = <<-SQL
6
+ CREATE TABLE IF NOT EXISTS Items (
7
+ id INTEGER PRIMARY KEY,
8
+ content TEXT,
9
+ list_id INTEGER,
10
+ done BOOLEAN DEFAULT false
11
+ )
12
+ SQL
13
+
14
+ lists_sql = <<-SQL
15
+ CREATE TABLE IF NOT EXISTS Lists (
16
+ id INTEGER PRIMARY KEY,
17
+ title VARCHAR
18
+ )
19
+ SQL
20
+
21
+
22
+
23
+ DB.execute(items_sql)
24
+ DB.execute(lists_sql)
25
+ end
@@ -0,0 +1,3 @@
1
+ module TodoLists
2
+ VERSION = "0.2.0"
3
+ end
data/lib/todo_lists.rb ADDED
@@ -0,0 +1,20 @@
1
+ require "todo_lists/version"
2
+ require 'sqlite3'
3
+ require 'active_record'
4
+ require 'todo_lists/setup_database'
5
+
6
+ ActiveRecord::Base.establish_connection(
7
+ database: "#{Dir.home}/.todo_lists",
8
+ adapter: 'sqlite3'
9
+ )
10
+
11
+ require 'todo_lists/models/list'
12
+ require 'todo_lists/models/item'
13
+
14
+ require 'todo_lists/controllers/cli'
15
+ require 'todo_lists/controllers/lists_controller'
16
+ require 'todo_lists/controllers/items_controller'
17
+
18
+ # create a database in the home directory if not exists
19
+ # establish_connection to the home directory database
20
+ #
@@ -0,0 +1,36 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "todo_lists/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "todo_lists"
7
+ spec.version = TodoLists::VERSION
8
+ spec.authors = ["Aurangzaib"]
9
+ spec.email = ["aurangzaib.danial@gmail.com"]
10
+
11
+ spec.summary = "Quickly make todo lists using terminal"
12
+ spec.description = "Allow users to be able to make todo lists without moving away from terminal, all the lists are persisted to database. \nYou need to have sqlite installed on your computer before hand http://www.sqlite.org"
13
+ spec.homepage = "https://github.com/aurangzaib-danial/todo_lists"
14
+ spec.license = "MIT"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/aurangzaib-danial/todo_lists"
18
+ spec.metadata["changelog_uri"] = "https://github.com/aurangzaib-danial/todo_lists"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 2.0"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "rspec", "~> 3.0"
32
+ spec.add_development_dependency "pry", "~> 0.12.2"
33
+ spec.add_development_dependency "sinatra-activerecord", "2.0.14"
34
+ spec.add_dependency "activerecord", "~> 5.2"
35
+ spec.add_dependency "sqlite3", "1.3.13"
36
+ end
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: todo_lists
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Aurangzaib
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-10-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.12.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.12.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: sinatra-activerecord
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 2.0.14
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 2.0.14
83
+ - !ruby/object:Gem::Dependency
84
+ name: activerecord
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '5.2'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '5.2'
97
+ - !ruby/object:Gem::Dependency
98
+ name: sqlite3
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 1.3.13
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 1.3.13
111
+ description: "Allow users to be able to make todo lists without moving away from terminal,
112
+ all the lists are persisted to database. \nYou need to have sqlite installed on
113
+ your computer before hand http://www.sqlite.org"
114
+ email:
115
+ - aurangzaib.danial@gmail.com
116
+ executables:
117
+ - todo_lists
118
+ extensions: []
119
+ extra_rdoc_files: []
120
+ files:
121
+ - ".gitignore"
122
+ - ".rspec"
123
+ - ".travis.yml"
124
+ - CODE_OF_CONDUCT.md
125
+ - Gemfile
126
+ - Gemfile.lock
127
+ - LICENSE.txt
128
+ - README.md
129
+ - Rakefile
130
+ - TODO.md
131
+ - bin/console
132
+ - bin/setup
133
+ - config/environment.rb
134
+ - db/migrate/20191011142427_create_lists.rb
135
+ - db/migrate/20191011153440_create_items.rb
136
+ - db/migrate/20191012023313_add_done_to_items.rb
137
+ - db/schema.rb
138
+ - db/todo_lists.sqlite
139
+ - exe/todo_lists
140
+ - lib/todo_lists.rb
141
+ - lib/todo_lists/controllers/cli.rb
142
+ - lib/todo_lists/controllers/items_controller.rb
143
+ - lib/todo_lists/controllers/lists_controller.rb
144
+ - lib/todo_lists/models/item.rb
145
+ - lib/todo_lists/models/list.rb
146
+ - lib/todo_lists/setup_database.rb
147
+ - lib/todo_lists/version.rb
148
+ - todo_lists.gemspec
149
+ homepage: https://github.com/aurangzaib-danial/todo_lists
150
+ licenses:
151
+ - MIT
152
+ metadata:
153
+ homepage_uri: https://github.com/aurangzaib-danial/todo_lists
154
+ source_code_uri: https://github.com/aurangzaib-danial/todo_lists
155
+ changelog_uri: https://github.com/aurangzaib-danial/todo_lists
156
+ post_install_message:
157
+ rdoc_options: []
158
+ require_paths:
159
+ - lib
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubygems_version: 3.0.6
172
+ signing_key:
173
+ specification_version: 4
174
+ summary: Quickly make todo lists using terminal
175
+ test_files: []