myworklog 1.0.5
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 +7 -0
- data/bin/myworklog +3 -0
- data/lib/work_log.rb +13 -0
- data/lib/work_log_controller.rb +39 -0
- data/lib/work_log_file_dao.rb +42 -0
- data/lib/worklog_cli.rb +50 -0
- metadata +51 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 52edc3202c110eab72423c6c78978fdb6b350805a19735f62371ebd0b833f312
|
4
|
+
data.tar.gz: 2919dac5538aaedd39618dbf27f036d5fe83d37dea201f8228a17146a2459010
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aff6e16f652b5d413862b40f7b0118b710c5f69e9297530f6f7ff73f6e78b6888e42aac4d9d1cbde740c8e53b6cf76424e8f744e63099a2b2657a8b9c1bb1e4b
|
7
|
+
data.tar.gz: 13590defc6c36c214354cadbebb4b3e66e794217839294e8e760aee2e010737c5bb91124e9934527c9af3091389eb1527d23c8a59716aa457865b11b5bd1172b
|
data/bin/myworklog
ADDED
data/lib/work_log.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
require 'Date'
|
3
|
+
require_relative 'work_log_file_dao'
|
4
|
+
require_relative 'work_log'
|
5
|
+
|
6
|
+
class WorkLogController
|
7
|
+
|
8
|
+
def add_work_log(date, description)
|
9
|
+
WorkLogFileDao.new.save(create_work_log(date, description))
|
10
|
+
end
|
11
|
+
|
12
|
+
def list(date)
|
13
|
+
WorkLogFileDao.new.list(parse_date(date))
|
14
|
+
end
|
15
|
+
|
16
|
+
def list_all
|
17
|
+
WorkLogFileDao.new.list_all
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete(id)
|
21
|
+
WorkLogFileDao.new.delete(id)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def create_work_log(date, description)
|
27
|
+
WorkLog.new(SecureRandom.uuid, parse_date(date), description)
|
28
|
+
end
|
29
|
+
|
30
|
+
def parse_date(date)
|
31
|
+
if date.nil? || date.empty? || date.downcase == 'today'
|
32
|
+
Date.today
|
33
|
+
elsif date.downcase == 'yesterday'
|
34
|
+
Date.today.prev_day
|
35
|
+
else
|
36
|
+
Date::strptime(date, "%d/%m/%Y")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'pstore'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
class WorkLogFileDao
|
5
|
+
DB_FILE_NAME = 'myworklog.pstore'
|
6
|
+
DB_FOLDER = '.myworklog'
|
7
|
+
HOME_FOLDER = File.expand_path('~')
|
8
|
+
FULL_DB_FILE_PATH = "#{HOME_FOLDER}/#{DB_FOLDER}/#{DB_FILE_NAME}"
|
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
|
14
|
+
|
15
|
+
def save(work_log)
|
16
|
+
PStore.new(FULL_DB_FILE_PATH).transaction { |store| store[work_log.id] = work_log }
|
17
|
+
end
|
18
|
+
|
19
|
+
def list(date)
|
20
|
+
store = PStore.new(FULL_DB_FILE_PATH)
|
21
|
+
list = []
|
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
|
28
|
+
|
29
|
+
def list_all
|
30
|
+
store = PStore.new(FULL_DB_FILE_PATH)
|
31
|
+
list = []
|
32
|
+
store.transaction(true) { store.roots.map { |root| list << store[root] } }
|
33
|
+
list
|
34
|
+
end
|
35
|
+
|
36
|
+
def delete(id)
|
37
|
+
PStore.new(FULL_DB_FILE_PATH).transaction do |store|
|
38
|
+
raise Exception.new("Id #{id} not found") if store[id] == nil
|
39
|
+
store.delete(id)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/worklog_cli.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'date'
|
3
|
+
require_relative 'work_log_controller'
|
4
|
+
|
5
|
+
DATE_FORMAT = 'DD/MM/YYYY'
|
6
|
+
|
7
|
+
class WorkLogCli < Thor
|
8
|
+
desc 'add [DATE] [DESCRIPTION]', "adds a new work log. Use 'today' as DATE for current date or 'yesterday'. Date format #{DATE_FORMAT}"
|
9
|
+
|
10
|
+
def add(date, description)
|
11
|
+
WorkLogController.new.add_work_log(date, description)
|
12
|
+
end
|
13
|
+
|
14
|
+
desc 'list [DATE]', "prints work logs limited by DATE. Use 'today' or leave it empty for current day. Date format #{DATE_FORMAT}"
|
15
|
+
|
16
|
+
def list(date='')
|
17
|
+
print(WorkLogController.new.list(date))
|
18
|
+
end
|
19
|
+
|
20
|
+
desc 'list_all', "prints all the work logs"
|
21
|
+
|
22
|
+
def list_all
|
23
|
+
print(WorkLogController.new.list_all)
|
24
|
+
end
|
25
|
+
|
26
|
+
desc 'delete [ID]', 'Deletes the work log by ID. Use list command before to retrieve the ID'
|
27
|
+
|
28
|
+
def delete(id)
|
29
|
+
begin
|
30
|
+
WorkLogController.new.delete(id)
|
31
|
+
puts "Work log with #{id} ID has been deleted!"
|
32
|
+
rescue Exception => msg
|
33
|
+
puts msg
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def print(work_log_list)
|
40
|
+
puts ''
|
41
|
+
if work_log_list.empty?
|
42
|
+
puts 'Work log(s) not found'
|
43
|
+
elsif
|
44
|
+
work_log_list.each do |work_log|
|
45
|
+
puts "#{work_log.id} | #{work_log}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
puts ''
|
49
|
+
end
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: myworklog
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gyowanny Queiroz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-02-20 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Log your work from cmd and keep track of what you have done. Just in
|
14
|
+
case your boss asks
|
15
|
+
email:
|
16
|
+
- gyowanny@gmail.com
|
17
|
+
executables:
|
18
|
+
- myworklog
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- bin/myworklog
|
23
|
+
- lib/work_log.rb
|
24
|
+
- lib/work_log_controller.rb
|
25
|
+
- lib/work_log_file_dao.rb
|
26
|
+
- lib/worklog_cli.rb
|
27
|
+
homepage: http://rubygems.org/gems/myworklog
|
28
|
+
licenses:
|
29
|
+
- MIT
|
30
|
+
metadata:
|
31
|
+
source_code_uri: https://github.com/gyoqueiroz/myworklog
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
requirements: []
|
47
|
+
rubygems_version: 3.0.3
|
48
|
+
signing_key:
|
49
|
+
specification_version: 4
|
50
|
+
summary: My Work Log
|
51
|
+
test_files: []
|