hypertodo 1.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d493db5edd1eb7c2dc2efa67480573562f5b38ff
4
+ data.tar.gz: 21d1db2e8b4dd6e85df21b5723bd7255cee66c1b
5
+ SHA512:
6
+ metadata.gz: 506540e9e931e4bda3be1310997cd4361a9c278d0c4134c5249bae3a6509eacddec080aae71a834a55119de43b204f795d488d1f0cc51096279dce85fab43c35
7
+ data.tar.gz: 9aedb778d30904090d7ea8ed360753b1b4ab59bd9d4d2653f2352e8a3bd59ce005c7bf0e82f4c94550d6faeff39a8adc6b0f73b848a48f2ba2c5479f22f777a1
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hypertodo.gemspec
4
+ gemspec
5
+
6
+ gem 'pry'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 chansuke
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,41 @@
1
+ # Hypertodo
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/hypertodo`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'hypertodo'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install hypertodo
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec hypertodo` to use the gem in this directory, ignoring other installed copies of this gem.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/hypertodo. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require "bundler/gem_tasks"
2
+ require "yard"
3
+
4
+ YARD::Rake::YardocTask.new
data/bin/console ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "hypertodo"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ require "pry"
11
+ Pry.start
12
+
13
+ Todo::Command.run(ARGV)
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/exe/hypertodo ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "hypertodo"
data/hypertodo.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hypertodo/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hypertodo"
8
+ spec.version = Hypertodo::VERSION
9
+ spec.authors = ["chansuke"]
10
+ spec.email = ["moonset20@gmail.com"]
11
+
12
+ spec.summary = %q{Hyper task management tool}
13
+ spec.description = %q{To accelerate one's productivity}
14
+ spec.homepage = "https://github.com/chansuke/hypertodo"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "activerecord", "~> 3.2.0"
23
+ spec.add_dependency "sqlite3", "~> 1.3.0"
24
+ spec.add_development_dependency "bundler", "~> 1.10"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "yard", "~> 0.8"
27
+ spec.add_development_dependency "redcarpet", "~> 2.2"
28
+ end
data/lib/hypertodo.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "hypertodo/command"
2
+ require "hypertodo/command/options"
3
+ require "hypertodo/db"
4
+ require "hypertodo/task"
5
+ require "hypertodo/version"
6
+
7
+ module Hypertodo
8
+ # Your code goes here...
9
+ end
@@ -0,0 +1,86 @@
1
+ # coding: utf-8
2
+ class Command
3
+
4
+ def self.run(argv)
5
+ new(argv).execute
6
+ end
7
+
8
+ def initialize(argv)
9
+ @argv = argv
10
+ end
11
+
12
+ def execute
13
+ options = Options.parse!(@argv)
14
+ sub_command = options.delete(:command)
15
+
16
+ DB.prepare
17
+
18
+ tasks = case sub_command:
19
+ when 'create'
20
+ create_task(options[:name], options[:content])
21
+ when 'delete'
22
+ delete_task(options[:id])
23
+ when 'update'
24
+ update_task(options.delete(:id), options)
25
+ when 'list'
26
+ find_tasks(options[:status])
27
+ end
28
+ display_tasks tasks
29
+
30
+ rescue => e
31
+ abort "Error: #{e.message}"
32
+ end
33
+
34
+ def create_task(name, content)
35
+ Task.create!(name: name, content: content).reload
36
+ end
37
+
38
+ def delete_task(id)
39
+ task = Task.find(id)
40
+ task.destroy
41
+ end
42
+
43
+ def update_task(id, attributes)
44
+ if status_name = attributes[:status]
45
+ attributes[:status] = Task::STATUS.fetch(status_name.upcase)
46
+ end
47
+
48
+ task = Task.find(id)
49
+ task.update_attributes! attributes
50
+
51
+ task.reload
52
+ end
53
+
54
+ def find_tasks(status_name)
55
+ all_tasks = Task.order('created_at DESC')
56
+
57
+ if status_name
58
+ status = Task::STATUS.fetch(status_name.upcase)
59
+ all_tasks.status_is(status)
60
+ else
61
+ all_tasks
62
+ end
63
+ end
64
+
65
+ private
66
+
67
+ def display_tasks(tasks)
68
+ header = display_format('ID', 'Name', 'Content', 'Status')
69
+
70
+ puts header
71
+ puts '-' * header.size
72
+ Array(tasks).each do |task|
73
+ puts display_format(task.id, task.name, task.content, task.status_name)
74
+ end
75
+ end
76
+
77
+ def display_format(id, content, status)
78
+ name_length = 20 - full_width_count(name)
79
+ content_length = 40 = full_width_count(content)
80
+ [id.to_s.rjust(4), name.ljust(20), content,ljust(38), status.ljust(8)].join(' | ')
81
+ end
82
+
83
+ def full_width_count(string)
84
+ string.each_char.select{|char| !(/[ -~。-゜]/.match(char)) }.count
85
+ end
86
+ end
@@ -0,0 +1,100 @@
1
+ # coding: utf-8
2
+
3
+ require 'optparse'
4
+ module Options
5
+
6
+ def self.parse!(argv)
7
+ options = {}
8
+
9
+ sub_command_parsers = create_sub_command_parsers
10
+ command_parser = create_command_parser
11
+
12
+ begin
13
+ sub_command_parsers[options[:command]].parse! argv
14
+
15
+ if %w(update delete).include?(options[:command])
16
+ raise ArgumentError, "#{options[:command]} id not found." if argv.empty?
17
+ options[:id] = Integer(argv.first)
18
+ end
19
+ rescue OptionParser::MissingArgument, OptionParser::InvalidOption, ArgumentError => e
20
+ abort e.message
21
+ end
22
+ command_parser.order!(argv)
23
+
24
+ options[:command] = argv.shift
25
+
26
+ sub_command_parsers[options[:command]].parse!(argv)
27
+ rescue OptionParser::MissingArgument, OptionParser::InvalidOption, ArgumentError => e
28
+ abort e.message
29
+ end
30
+ end
31
+
32
+ def self.create_sub_command_parsers(options)
33
+ sub_command_parsers = Hash.new do |k, v|
34
+ raise ArgumentError, "'#{v}' is not todo sub command."
35
+ end
36
+
37
+ sub_command_parsers['create'] = OptionParser.new do |opt|
38
+ opt.banner = 'Usage: create <args>'
39
+ opt.on('-n VAL', '--name=VAL', 'task name') {|v| options[:name] = v }
40
+ opt.on('-c VAL', '--content=VAL', 'task content') {|v| options[:content] = v }
41
+ opt.on_tail('-h', '--help', 'Show this message') {|v| help_sub_command(opt) }
42
+ end
43
+
44
+ sub_command_parsers['list'] = OptionParser.new do |opt|
45
+ opt.banner = 'Usage: list <args>'
46
+ opt.on('-s VAL', '--status=VAL', 'list status') {|v| options[:status] = v }
47
+ opt.on_tail('-h', '--help', 'Show this message') {|v| help_sub_command(opt) }
48
+ end
49
+
50
+ sub_command_parsers['update'] = OptionParser.new do |opt|
51
+ opt.banner = 'Usage: update id <args>'
52
+ opt.on('-n VAL', '--name=VAL', 'update name') {|v| options[:name] = v }
53
+ opt.on('-c VAL', '--content=VAL' 'update content') {|v| options[:content] = v }
54
+ opt.on('-s VAL', '--status=VAL', 'update status') {|v| options[:status] = v }
55
+ opt.on_tail('-h', '--help', 'Shoe this message') {|v| help_sub_command(opt) }
56
+ end
57
+
58
+ sub_command_parsers['delete'] = OptionParser.new do |opt|
59
+ opt.banner = 'Usage: delete id'
60
+ opt.on_tail('-h', '--help', 'Show this message') {|v| help_sub_command(opt) }
61
+ end
62
+
63
+ sub_command_parsers
64
+ end
65
+
66
+ def self.help_sub_command(parser)
67
+ puts parser.help
68
+ exit
69
+ end
70
+
71
+ def self.create_command_parser
72
+ OptionParser.new do |opt|
73
+ sub_command_help = [
74
+ {name: 'create -n name -c content', summary: 'Create Todo Task'},
75
+ {name: 'update id -n name -c content -s status', summary: 'Update Todo Task'},
76
+ {name: 'list -s status', summary: 'List Todo Tasks'},
77
+ {name: 'delete id', summary: 'Delete Todo Task'}
78
+ ]
79
+ opt.banner = "Usage: #{opt.program_name} [-h|--help][-v|--version] <command> [<args>]"
80
+ opt.separator ''
81
+ opt.separator "#{opt.program_name} Available Commands:"
82
+ sub_command_help.each do |command|
83
+ opt.separator [opt.summary_indent, command[:name].ljust(40), command[:summary]].join(' ')
84
+ end
85
+
86
+ opt.on_head('-h', '--help', 'Show this message') do |v|
87
+ puts opt.help
88
+ exit
89
+ end
90
+
91
+ opt.on_head('-v', '--version', 'Show program version') do |v|
92
+ opt.version = Todo::VERSION
93
+ puts opt.ver
94
+ exit
95
+ end
96
+ end
97
+ end
98
+
99
+ private_class_method :create_sub_command_parsers, :create_command_parser, :help_sub_command
100
+ end
@@ -0,0 +1,45 @@
1
+ # coding: utf-8
2
+
3
+ require 'fileutils'
4
+ require 'active_record'
5
+
6
+ module HyperTodo
7
+
8
+ module DB
9
+ def self.prepare
10
+ database_path = File.join(ENV['HOME'], '.todo', 'todo.sqlite3')
11
+
12
+ connect_database database_path
13
+ create_table_if_not_exists database_path
14
+ end
15
+
16
+ def self.connect_database(path)
17
+ spec = {adapter: 'sqlite3', database: path}
18
+ ActiveRecord::Base.establish_connection spec
19
+ end
20
+
21
+ def self.create_table_if_not_exists(path)
22
+ create_database_path path
23
+
24
+ connection = ActiveRecord::Base.connection
25
+
26
+ return if connection.table_exists?(:tasks)
27
+
28
+ connection.create_table :tasks do |t|
29
+ t.column :name, :string, null: false
30
+ t.column :content, :text, null: false
31
+ t.column :status, :integer, default: 0, null: false
32
+ t.timestamps
33
+ end
34
+ connection.add_index :tasks, :status
35
+ connection.add_index :tasks, :created_at
36
+ end
37
+
38
+ def self.create_database_path(path)
39
+ FileUtils.mkdir_p File.dirname(path)
40
+ end
41
+
42
+ private_class_method :connect_database, :create_table_if_not_exists, :create_database_path
43
+ end
44
+
45
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+
3
+ require 'active_record'
4
+
5
+ module HyperTodo
6
+
7
+ class Task < ActiveRecord::Base
8
+ scope :status_is, ->(status) { where(status: status) }
9
+ NOT_YET = 0
10
+ DONE = 1
11
+ PENDING = 2
12
+ STATUS = {
13
+ 'NOT_YET' => NOT_YET,
14
+ 'DONE' => DONE,
15
+ 'PENDING' => PENDING
16
+ }.freeze
17
+ validates :name, presence: true, length: {maximum: 140}
18
+ validates :content, presence: true
19
+ validates :status, numericality: true, inclusion: {in: STATUS.values}
20
+ def status_name
21
+ STATUS.key(self.status)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module Hypertodo
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hypertodo
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - chansuke
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 3.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 3.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.3.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.3.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: yard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.8'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.8'
83
+ - !ruby/object:Gem::Dependency
84
+ name: redcarpet
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.2'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.2'
97
+ description: To accelerate one's productivity
98
+ email:
99
+ - moonset20@gmail.com
100
+ executables:
101
+ - hypertodo
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".travis.yml"
107
+ - CODE_OF_CONDUCT.md
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - exe/hypertodo
115
+ - hypertodo.gemspec
116
+ - lib/hypertodo.rb
117
+ - lib/hypertodo/command.rb
118
+ - lib/hypertodo/command/options.rb
119
+ - lib/hypertodo/db.rb
120
+ - lib/hypertodo/task.rb
121
+ - lib/hypertodo/version.rb
122
+ homepage: https://github.com/chansuke/hypertodo
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.4.5
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: Hyper task management tool
146
+ test_files: []
147
+ has_rdoc: