myworklog 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/work_log.rb +12 -10
- data/lib/work_log_controller.rb +42 -41
- data/lib/work_log_file_dao.rb +56 -46
- data/lib/worklog_cli.rb +61 -53
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 694b96c440effe98b20dea018f6bf98f2eff3c93efaa57733a8e2db001531225
|
4
|
+
data.tar.gz: cdf1f7fd2db0bed741c68bb3c99ed2af1dd99b7c12793c35c68974cd5fa7a2c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41dcf2cd09f51b0667e32b6137aaf360b3aaa975f1f4809f1cebb81a66f336c997c02b13489f71da0fa705053cb74c88bd5e80ef8a1b19288c79be468cf058d2
|
7
|
+
data.tar.gz: 857ffa80fbdc6bb05d2a73d4de1c15ba751085a22d776312243c848b49757ff623990f0bae2ad85001aa2c8051834f0387cd8f2fc23a62869e48a0d157226699
|
data/lib/work_log.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class WorkLog
|
2
|
-
|
4
|
+
attr_reader :id, :date, :description
|
3
5
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
def initialize(id, date, description)
|
7
|
+
@id = id
|
8
|
+
@date = date
|
9
|
+
@description = description
|
10
|
+
end
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
12
|
+
def to_s
|
13
|
+
"#{@date.strftime('%d/%m/%Y')} - #{@description}"
|
14
|
+
end
|
15
|
+
end
|
data/lib/work_log_controller.rb
CHANGED
@@ -1,47 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'securerandom'
|
2
4
|
require 'Date'
|
3
5
|
require_relative 'work_log_file_dao'
|
4
6
|
require_relative 'work_log'
|
5
7
|
|
6
8
|
class WorkLogController
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
9
|
+
def add_work_log(date, description)
|
10
|
+
WorkLogFileDao.new.save(create_work_log(date, description))
|
11
|
+
end
|
12
|
+
|
13
|
+
def list(date)
|
14
|
+
WorkLogFileDao.new.list(parse_date(date))
|
15
|
+
end
|
16
|
+
|
17
|
+
def list_all
|
18
|
+
WorkLogFileDao.new.list_all
|
19
|
+
end
|
20
|
+
|
21
|
+
def delete(id)
|
22
|
+
WorkLogFileDao.new.delete(id)
|
23
|
+
end
|
24
|
+
|
25
|
+
def find_by_month_and_year(month, year)
|
26
|
+
WorkLogFileDao.new.find_by_month_and_year(month, year)
|
27
|
+
end
|
28
|
+
|
29
|
+
def find_by_year(year)
|
30
|
+
WorkLogFileDao.new.find_by_year(year)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def create_work_log(date, description)
|
36
|
+
WorkLog.new(SecureRandom.uuid, parse_date(date), description)
|
37
|
+
end
|
38
|
+
|
39
|
+
def parse_date(date)
|
40
|
+
if date.nil? || date.empty? || date.downcase == 'today'
|
41
|
+
Date.today
|
42
|
+
elsif date.downcase == 'yesterday'
|
43
|
+
Date.today.prev_day
|
44
|
+
else
|
45
|
+
Date.strptime(date, '%d/%m/%Y')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/work_log_file_dao.rb
CHANGED
@@ -1,62 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'pstore'
|
2
4
|
require 'fileutils'
|
3
5
|
|
4
6
|
class WorkLogFileDao
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
def initialize
|
11
|
-
db_folder_full_path = "#{HOME_FOLDER}/#{DB_FOLDER}"
|
12
|
-
FileUtils.mkdir_p(db_folder_full_path) unless File.directory?(db_folder_full_path)
|
13
|
-
end
|
7
|
+
DB_FILE_NAME = 'myworklog.pstore'
|
8
|
+
DB_FOLDER = '.myworklog'
|
9
|
+
HOME_FOLDER = File.expand_path('~')
|
10
|
+
FULL_DB_FILE_PATH = "#{HOME_FOLDER}/#{DB_FOLDER}/#{DB_FILE_NAME}"
|
14
11
|
|
15
|
-
|
16
|
-
|
12
|
+
def initialize
|
13
|
+
db_folder_full_path = "#{HOME_FOLDER}/#{DB_FOLDER}"
|
14
|
+
unless File.directory?(db_folder_full_path)
|
15
|
+
FileUtils.mkdir_p(db_folder_full_path)
|
17
16
|
end
|
17
|
+
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
store.transaction(true) do
|
23
|
-
store.roots
|
24
|
-
.map { |root| list << store[root] if store[root].date == date }
|
25
|
-
end
|
26
|
-
list
|
27
|
-
end
|
19
|
+
def save(work_log)
|
20
|
+
PStore.new(FULL_DB_FILE_PATH).transaction { |store| store[work_log.id] = work_log }
|
21
|
+
end
|
28
22
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
23
|
+
def list(date)
|
24
|
+
store = PStore.new(FULL_DB_FILE_PATH)
|
25
|
+
list = []
|
26
|
+
store.transaction(true) do
|
27
|
+
store.roots
|
28
|
+
.map { |root| list << store[root] if store[root].date == date }
|
34
29
|
end
|
30
|
+
list
|
31
|
+
end
|
35
32
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
33
|
+
def list_all
|
34
|
+
store = PStore.new(FULL_DB_FILE_PATH)
|
35
|
+
list = []
|
36
|
+
store.transaction(true) { store.roots.map { |root| list << store[root] } }
|
37
|
+
list
|
38
|
+
end
|
39
|
+
|
40
|
+
def delete(id)
|
41
|
+
PStore.new(FULL_DB_FILE_PATH).transaction do |store|
|
42
|
+
raise Exception, "Id #{id} not found" if store[id].nil?
|
43
|
+
|
44
|
+
store.delete(id)
|
41
45
|
end
|
46
|
+
end
|
42
47
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
48
|
+
def find_by_month_and_year(month, year)
|
49
|
+
store = PStore.new(FULL_DB_FILE_PATH)
|
50
|
+
list = []
|
51
|
+
store.transaction(true) do
|
52
|
+
store.roots.map do |root|
|
53
|
+
if store[root].date.month == month && store[root].date.year == year
|
54
|
+
list << store[root]
|
49
55
|
end
|
50
|
-
|
56
|
+
end
|
51
57
|
end
|
58
|
+
list
|
59
|
+
end
|
52
60
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
+
def find_by_year(year)
|
62
|
+
store = PStore.new(FULL_DB_FILE_PATH)
|
63
|
+
list = []
|
64
|
+
store.transaction(true) do
|
65
|
+
store.roots
|
66
|
+
.map do |root|
|
67
|
+
list << store[root] if store[root].date.year == year
|
68
|
+
end
|
61
69
|
end
|
62
|
-
|
70
|
+
list
|
71
|
+
end
|
72
|
+
end
|
data/lib/worklog_cli.rb
CHANGED
@@ -1,25 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'thor'
|
2
4
|
require 'date'
|
5
|
+
require 'rubygems'
|
3
6
|
require_relative 'work_log_controller'
|
4
7
|
|
5
8
|
DATE_FORMAT = 'DD/MM/YYYY'
|
6
9
|
|
7
10
|
class WorkLogCli < Thor
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
11
|
+
map %w[--version -v] => :__print_version
|
12
|
+
|
13
|
+
desc 'add [DESCRIPTION]', "Adds a new work log with today's date as default. Use -d flag to specify a different date (e.g. myworklog add -d 10/10/2010 'I worked'). Date format #{DATE_FORMAT}"
|
14
|
+
options d: :string
|
15
|
+
def add(description)
|
16
|
+
date = options[:d] || 'today'
|
17
|
+
WorkLogController.new.add_work_log(date, description)
|
18
|
+
rescue ArgumentError => e
|
19
|
+
puts e
|
20
|
+
end
|
21
|
+
|
22
|
+
desc 'list', "Prints work logs for the current date. Date format #{DATE_FORMAT}"
|
23
|
+
long_desc <<-LONGDESC
|
21
24
|
Prints work logs for the current date if no option specified.
|
22
|
-
|
25
|
+
|
23
26
|
Availble options:
|
24
27
|
|
25
28
|
With -m option, prints all the work logs for the specified month, assumes the current year
|
@@ -36,49 +39,54 @@ class WorkLogCli < Thor
|
|
36
39
|
|
37
40
|
`myworklog -y 2020` Will print all the work logs logged in 2020
|
38
41
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
42
|
+
LONGDESC
|
43
|
+
options m: :numeric
|
44
|
+
options y: :numeric
|
45
|
+
def list(date = '')
|
46
|
+
if options[:m] && options[:y]
|
47
|
+
print(WorkLogController.new.find_by_month_and_year(options[:m], options[:y]))
|
48
|
+
elsif options[:m] && options[:y].nil?
|
49
|
+
print(WorkLogController.new.find_by_month_and_year(options[:m], Date.today.year))
|
50
|
+
elsif options[:m].nil? && options[:y]
|
51
|
+
print(WorkLogController.new.find_by_year(options[:y]))
|
52
|
+
else
|
53
|
+
print(WorkLogController.new.list(date))
|
52
54
|
end
|
55
|
+
end
|
53
56
|
|
54
|
-
|
57
|
+
desc 'list_all', 'prints all the work logs'
|
55
58
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
+
def list_all
|
60
|
+
print(WorkLogController.new.list_all)
|
61
|
+
end
|
59
62
|
|
60
|
-
|
63
|
+
desc 'delete [ID]', 'Deletes the work log by ID. You can use the `list` command to retrieve the ID'
|
61
64
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
65
|
+
def delete(id)
|
66
|
+
WorkLogController.new.delete(id)
|
67
|
+
puts "Work log with #{id} ID has been deleted!"
|
68
|
+
rescue Exception => e
|
69
|
+
puts e
|
70
|
+
end
|
71
|
+
|
72
|
+
desc '--version -v', 'Prints the current version'
|
73
|
+
|
74
|
+
def __print_version
|
75
|
+
spec = Gem::Specification.load('myworklog.gemspec')
|
76
|
+
puts spec.version
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
70
80
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
puts "#{work_log.id} | #{work_log}"
|
80
|
-
end
|
81
|
-
end
|
82
|
-
puts ''
|
81
|
+
def print(work_log_list)
|
82
|
+
puts ''
|
83
|
+
if work_log_list.empty?
|
84
|
+
puts 'Work log(s) not found'
|
85
|
+
else
|
86
|
+
work_log_list.each do |work_log|
|
87
|
+
puts "#{work_log.id} | #{work_log}"
|
88
|
+
end
|
83
89
|
end
|
84
|
-
|
90
|
+
puts ''
|
91
|
+
end
|
92
|
+
end
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: myworklog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gyowanny Queiroz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-02-
|
11
|
+
date: 2020-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: Log your work from cmd and keep track of what you have done
|
14
|
-
case your boss
|
13
|
+
description: Log your work from cmd and keep track of what you have done... just in
|
14
|
+
case your boss ask
|
15
15
|
email:
|
16
16
|
- gyowanny@gmail.com
|
17
17
|
executables:
|