hypertodo 1.0.0 → 1.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d493db5edd1eb7c2dc2efa67480573562f5b38ff
4
- data.tar.gz: 21d1db2e8b4dd6e85df21b5723bd7255cee66c1b
3
+ metadata.gz: 7943f78b505274eb89f357b34380b166e4f6b2a0
4
+ data.tar.gz: 01b1213c8b66b36394310437899fb44e023fa52b
5
5
  SHA512:
6
- metadata.gz: 506540e9e931e4bda3be1310997cd4361a9c278d0c4134c5249bae3a6509eacddec080aae71a834a55119de43b204f795d488d1f0cc51096279dce85fab43c35
7
- data.tar.gz: 9aedb778d30904090d7ea8ed360753b1b4ab59bd9d4d2653f2352e8a3bd59ce005c7bf0e82f4c94550d6faeff39a8adc6b0f73b848a48f2ba2c5479f22f777a1
6
+ metadata.gz: 5c6b8b11a87cb0cfbe19f02c83122e218fd13f395701e39fe4a1634121ed34bcc486053c98ec030bb25ed902caafa2542b81360932a62c8d3ac45cde327d1a2d
7
+ data.tar.gz: 4a16a50810440e70164e0c01931beba2325ce5e833961f426f0fbad283411f02bafd85ffd16faf67105e2239afaef91486554f81942f050697fbf915c99e0725
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'hypertodo'
4
+
5
+ Hypertodo::Command.run(ARGV)
@@ -4,6 +4,3 @@ require "hypertodo/db"
4
4
  require "hypertodo/task"
5
5
  require "hypertodo/version"
6
6
 
7
- module Hypertodo
8
- # Your code goes here...
9
- end
@@ -1,86 +1,92 @@
1
1
  # coding: utf-8
2
- class Command
3
2
 
4
- def self.run(argv)
5
- new(argv).execute
6
- end
3
+ module Hypertodo
7
4
 
8
- def initialize(argv)
9
- @argv = argv
10
- end
5
+ class Command
11
6
 
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
7
+ def self.run(argv)
8
+ new(argv).execute
9
+ end
33
10
 
34
- def create_task(name, content)
35
- Task.create!(name: name, content: content).reload
36
- end
11
+ def initialize(argv)
12
+ @argv = argv
13
+ end
37
14
 
38
- def delete_task(id)
39
- task = Task.find(id)
40
- task.destroy
41
- end
15
+ def execute
16
+ options = Options.parse!(@argv)
17
+ sub_command = options.delete(:command)
18
+
19
+ DB.prepare
20
+
21
+ tasks = case sub_command
22
+ when 'create'
23
+ create_task(options[:name], options[:content])
24
+ when 'delete'
25
+ delete_task(options[:id])
26
+ when 'update'
27
+ update_task(options.delete(:id), options)
28
+ when 'list'
29
+ find_tasks(options[:status])
30
+ end
31
+ display_tasks tasks
32
+
33
+ rescue => e
34
+ abort "Error: #{e.message}"
35
+ end
42
36
 
43
- def update_task(id, attributes)
44
- if status_name = attributes[:status]
45
- attributes[:status] = Task::STATUS.fetch(status_name.upcase)
37
+ def create_task(name, content)
38
+ # タスク作成時のstatusはデフォルト値が使われNOT_YETとなる
39
+ Task.create!(name: name, content: content).reload
46
40
  end
47
41
 
48
- task = Task.find(id)
49
- task.update_attributes! attributes
42
+ def delete_task(id)
43
+ task = Task.find(id)
44
+ task.destroy
45
+ end
50
46
 
51
- task.reload
52
- end
47
+ def update_task(id, attributes)
48
+ if status_name = attributes[:status]
49
+ attributes[:status] = Task::STATUS.fetch(status_name.upcase)
50
+ end
53
51
 
54
- def find_tasks(status_name)
55
- all_tasks = Task.order('created_at DESC')
52
+ task = Task.find(id)
53
+ task.update_attributes! attributes
56
54
 
57
- if status_name
58
- status = Task::STATUS.fetch(status_name.upcase)
59
- all_tasks.status_is(status)
60
- else
61
- all_tasks
55
+ task.reload
62
56
  end
63
- end
64
57
 
65
- private
58
+ def find_tasks(status_name)
59
+ all_tasks = Task.order('created_at DESC')
60
+
61
+ if status_name
62
+ status = Task::STATUS.fetch(status_name.upcase)
63
+ all_tasks.status_is(status)
64
+ else
65
+ all_tasks
66
+ end
67
+ end
66
68
 
67
- def display_tasks(tasks)
68
- header = display_format('ID', 'Name', 'Content', 'Status')
69
+ private
69
70
 
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)
71
+ def display_tasks(tasks)
72
+ header = display_format('ID', 'Name', 'Content', 'Status')
73
+
74
+ puts header
75
+ puts '-' * header.size
76
+ Array(tasks).each do |task|
77
+ puts display_format(task.id, task.name, task.content, task.status_name)
78
+ end
74
79
  end
75
- end
76
80
 
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
81
+ def display_format(id, name, content, status)
82
+ name_length = 20 - full_width_count(name)
83
+ content_length = 38 - full_width_count(content)
84
+ [id.to_s.rjust(4), name.ljust(name_length), content.ljust(content_length), status.ljust(8)].join(' | ')
85
+ end
82
86
 
83
- def full_width_count(string)
84
- string.each_char.select{|char| !(/[ -~。-゜]/.match(char)) }.count
87
+ def full_width_count(string)
88
+ string.each_char.select{ |char| !(/[ -~。-゚]/.match(char)) }.count
89
+ end
85
90
  end
91
+
86
92
  end
@@ -1,100 +1,113 @@
1
1
  # coding: utf-8
2
2
 
3
3
  require 'optparse'
4
- module Options
5
4
 
6
- def self.parse!(argv)
7
- options = {}
5
+ module Hypertodo
8
6
 
9
- sub_command_parsers = create_sub_command_parsers
10
- command_parser = create_command_parser
7
+ class Command
11
8
 
12
- begin
13
- sub_command_parsers[options[:command]].parse! argv
9
+ module Options
14
10
 
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
11
+ def self.parse!(argv)
12
+ options = {}
25
13
 
26
- sub_command_parsers[options[:command]].parse!(argv)
27
- rescue OptionParser::MissingArgument, OptionParser::InvalidOption, ArgumentError => e
28
- abort e.message
29
- end
30
- end
14
+ sub_command_parsers = create_sub_command_parsers
15
+ command_parser = create_command_parser
31
16
 
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
17
+ # analysis
18
+ begin
19
+ command_parser.order! argv
36
20
 
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
21
+ options[:command] = argv.shift
43
22
 
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
23
+ sub_command_parsers[options[:command]].parse! argv
49
24
 
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
25
+ if %w(update delete).include?(options[:command])
26
+ raise ArgumentError, "#{options[:command]} id not found." if argv.empty?
27
+ options[:id] = Integer(argv.first)
28
+ end
29
+ rescue OptionParser::MissingArgument, OptionParser::InvalidOption, ArgumentError => e
30
+ abort e.message
31
+ end
57
32
 
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
33
+ options
34
+ end
70
35
 
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(' ')
36
+ def self.create_sub_command_parsers(options)
37
+ sub_command_parsers = Hash.new do |k, v|
38
+ raise ArgumentError, "'#{v}' is not todo sub command."
39
+ end
40
+
41
+ sub_command_parsers['create'] = OptionParser.new do |opt|
42
+ opt.banner = 'Usage: create <args>'
43
+ opt.on('-n VAL', '--name=VAL', 'task name') {|v| options[:name] = v }
44
+ opt.on('-c VAL', '--content=VAL', 'task content') {|v| options[:content] = v }
45
+ opt.on_tail('-h', '--help', 'Show this message') {|v| help_sub_command(opt) }
46
+ end
47
+
48
+ sub_command_parsers['list'] = OptionParser.new do |opt|
49
+ opt.banner = 'Usage: list <args>'
50
+ opt.on('-s VAL', '--status=VAL', 'list status') {|v| options[:status] = v }
51
+ opt.on_tail('-h', '--help', 'Show this message') {|v| help_sub_command(opt) }
52
+ end
53
+
54
+ sub_command_parsers['update'] = OptionParser.new do |opt|
55
+ opt.banner = 'Usage: update id <args>'
56
+ opt.on('-n VAL', '--name=VAL', 'update name') {|v| options[:name] = v }
57
+ opt.on('-c VAL', '--content=VAL' 'update content') {|v| options[:content] = v }
58
+ opt.on('-s VAL', '--status=VAL', 'update status') {|v| options[:status] = v }
59
+ opt.on_tail('-h', '--help', 'Shoe this message') {|v| help_sub_command(opt) }
60
+ end
61
+
62
+ sub_command_parsers['delete'] = OptionParser.new do |opt|
63
+ opt.banner = 'Usage: delete id'
64
+ opt.on_tail('-h', '--help', 'Show this message') {|v| help_sub_command(opt) }
65
+ end
66
+
67
+ sub_command_parsers
84
68
  end
85
69
 
86
- opt.on_head('-h', '--help', 'Show this message') do |v|
87
- puts opt.help
70
+ def self.help_sub_command(parser)
71
+ puts parser.help
88
72
  exit
89
73
  end
90
74
 
91
- opt.on_head('-v', '--version', 'Show program version') do |v|
92
- opt.version = Todo::VERSION
93
- puts opt.ver
75
+ def self.create_command_parser
76
+ OptionParser.new do |opt|
77
+ sub_command_help = [
78
+ {name: 'create -n name -c content', summary: 'Create Todo Task'},
79
+ {name: 'update id -n name -c content -s status', summary: 'Update Todo Task'},
80
+ {name: 'list -s status', summary: 'List Todo Tasks'},
81
+ {name: 'delete id', summary: 'Delete Todo Task'}
82
+ ]
83
+ opt.banner = "Usage: #{opt.program_name} [-h|--help][-v|--version] <command> [<args>]"
84
+ opt.separator ''
85
+ opt.separator "#{opt.program_name} Available Commands:"
86
+ sub_command_help.each do |command|
87
+ opt.separator [opt.summary_indent, command[:name].ljust(40), command[:summary]].join(' ')
88
+ end
89
+
90
+ opt.on_head('-h', '--help', 'Show this message') do |v|
91
+ puts opt.help
92
+ exit
93
+ end
94
+
95
+ opt.on_head('-v', '--version', 'Show program version') do |v|
96
+ opt.version = Todo::VERSION
97
+ puts opt.ver
98
+ exit
99
+ end
100
+ end
101
+ end
102
+
103
+ def self.help_sub_command(parser)
104
+ puts parse.help
94
105
  exit
95
106
  end
107
+
108
+ private_class_method :create_sub_command_parsers, :create_command_parser, :help_sub_command
96
109
  end
110
+
97
111
  end
98
112
 
99
- private_class_method :create_sub_command_parsers, :create_command_parser, :help_sub_command
100
113
  end
@@ -1,3 +1,3 @@
1
1
  module Hypertodo
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hypertodo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - chansuke
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-16 00:00:00.000000000 Z
11
+ date: 2015-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -109,8 +109,7 @@ files:
109
109
  - LICENSE.txt
110
110
  - README.md
111
111
  - Rakefile
112
- - bin/console
113
- - bin/setup
112
+ - bin/hypertodo
114
113
  - exe/hypertodo
115
114
  - hypertodo.gemspec
116
115
  - lib/hypertodo.rb
@@ -1,13 +0,0 @@
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 DELETED
@@ -1,7 +0,0 @@
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