check_list 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.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +4 -0
  3. data/README.md +48 -0
  4. data/bin/check-list +6 -0
  5. data/lib/build/asset-manifest.json +15 -0
  6. data/lib/build/cross.ico +0 -0
  7. data/lib/build/data.json +254 -0
  8. data/lib/build/favicon.ico +0 -0
  9. data/lib/build/index.html +1 -0
  10. data/lib/build/list.ico +0 -0
  11. data/lib/build/manifest.json +25 -0
  12. data/lib/build/robots.txt +3 -0
  13. data/lib/build/static/css/main.f784b531.css +9 -0
  14. data/lib/build/static/css/main.f784b531.css.map +1 -0
  15. data/lib/build/static/js/787.46b4d4fc.chunk.js +2 -0
  16. data/lib/build/static/js/787.46b4d4fc.chunk.js.map +1 -0
  17. data/lib/build/static/js/main.8c659df8.js +3 -0
  18. data/lib/build/static/js/main.8c659df8.js.LICENSE.txt +47 -0
  19. data/lib/build/static/js/main.8c659df8.js.map +1 -0
  20. data/lib/build/static/js/main.8f3bcf6c.js +3 -0
  21. data/lib/build/static/js/main.8f3bcf6c.js.LICENSE.txt +47 -0
  22. data/lib/build/static/js/main.8f3bcf6c.js.map +1 -0
  23. data/lib/build/static/js/main.ba318bd4.js +3 -0
  24. data/lib/build/static/js/main.ba318bd4.js.LICENSE.txt +47 -0
  25. data/lib/build/static/js/main.ba318bd4.js.map +1 -0
  26. data/lib/build/static/js/main.cc14af32.js +3 -0
  27. data/lib/build/static/js/main.cc14af32.js.LICENSE.txt +45 -0
  28. data/lib/build/static/js/main.cc14af32.js.map +1 -0
  29. data/lib/build/tick.ico +0 -0
  30. data/lib/check_list.rb +87 -0
  31. data/lib/checklist.json +137 -0
  32. data/lib/config.rb +43 -0
  33. data/lib/display_results.rb +50 -0
  34. data/lib/exceptions.rb +27 -0
  35. data/lib/handle_file.rb +35 -0
  36. data/lib/helpers.rb +79 -0
  37. data/lib/list.rb +21 -0
  38. data/lib/menu.rb +107 -0
  39. data/lib/results.rb +126 -0
  40. data/lib/results_publisher.rb +53 -0
  41. data/lib/symbolize.rb +39 -0
  42. data/lib/update.rb +156 -0
  43. data/lib/validations.rb +31 -0
  44. data/lib/view.rb +19 -0
  45. metadata +86 -0
data/lib/results.rb ADDED
@@ -0,0 +1,126 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'fileutils'
5
+ require_relative 'config'
6
+ require_relative 'helpers'
7
+ require_relative 'handle_file'
8
+ require_relative 'exceptions'
9
+ require_relative 'results_publisher'
10
+ require_relative 'display_results'
11
+
12
+ module CheckList
13
+ # Class to build the selection menu
14
+ class Results
15
+ attr_reader :results
16
+
17
+ def initialize(opts)
18
+ @ref = nil
19
+ @opts = opts
20
+ @results_array = []
21
+ @results = {}
22
+ process_opts
23
+ end
24
+
25
+ def process_opts
26
+ return @ref = @opts[:ref] unless @opts[:ref].nil?
27
+
28
+ @ref = 'main'
29
+ begin
30
+ branch = CheckList::Helpers.system_cmd("git status | grep 'On branch'")
31
+ @ref = branch.chomp.gsub(/On branch /, '')
32
+ rescue StandardError
33
+ CheckList::Helpers.log 'Error with branch, using default'
34
+ end
35
+ @ref
36
+ end
37
+
38
+ def process_value(list, value, task, sub_task)
39
+ result = {
40
+ 'list': list['name'],
41
+ 'task': task['name'],
42
+ 'subTask': sub_task['name'],
43
+ 'value': value,
44
+ 'timestamp': CheckList::Config.time_now
45
+ }
46
+ @results_array.push result
47
+ end
48
+
49
+ def process_results
50
+ CheckList::Helpers.clear
51
+
52
+ begin
53
+ create_results_list
54
+ create_tasks
55
+ add_sub_tasks
56
+ update_tasks
57
+ CheckList::ResultsPublisher.new(@results)
58
+ CheckList::DisplayResults.new(@results)
59
+ rescue CheckList::Exceptions::InvalidListError => e
60
+ CheckList::Helpers.log "Invalid List: #{e}"
61
+ CheckList::Helpers.leave
62
+ rescue StandardError => e
63
+ CheckList::Helpers.log "Error: #{e}"
64
+ CheckList::Helpers.leave
65
+ end
66
+ end
67
+
68
+ private
69
+
70
+ def update_tasks
71
+ @results[:tasks].each_with_index do |result, index|
72
+ status = 'n'
73
+ result[:subTasks].each do |sub_task|
74
+ if sub_task[:status] == 'n'
75
+ status = 'n'
76
+ break
77
+ else
78
+ status = 'y'
79
+ end
80
+ end
81
+ @results[:tasks][index][:status] = status
82
+ @results[:tasks][index][:user] = ENV.fetch('USER')
83
+ @results[:tasks][index][:time] = CheckList::Config.time_now
84
+ end
85
+ end
86
+
87
+ def add_sub_tasks
88
+ @results_array.each do |result|
89
+ task = @results[:tasks].index do |e|
90
+ e[:name] == result[:task]
91
+ end
92
+
93
+ res_hash = { name: result[:subTask], status: result[:value], time: result[:timestamp], user: ENV.fetch('USER') }
94
+ @results[:tasks][task][:subTasks].push res_hash
95
+ end
96
+ end
97
+
98
+ def create_tasks
99
+ @results[:tasks] = []
100
+ @results_array.each do |result|
101
+ res = { name: result[:task], status: 'n', time: '', subTasks: [] }
102
+ raise CheckList::Exceptions::InvalidListError, 'The list does not have a name' if @results[:name].nil?
103
+
104
+ if @results[:tasks].empty?
105
+ @results[:tasks].push res
106
+ elsif @results[:tasks].include? name: result[:task], status: 'n', time: '', subTasks: []
107
+ next
108
+ else
109
+ @results[:tasks].push res
110
+ end
111
+ end
112
+ end
113
+
114
+ def create_results_list
115
+ @results[:name] = nil
116
+ @results[:ref] = @ref
117
+ @results_array.each do |result|
118
+ if @results[:name].nil?
119
+ @results[:name] = result[:list]
120
+ elsif @results[:name] != result[:list]
121
+ raise CheckList::Exceptions::InvalidListError, 'The list can only contain one list title'
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'fileutils'
5
+ require_relative 'config'
6
+
7
+ module CheckList
8
+ # Publish the results of a completed checklist
9
+ class ResultsPublisher
10
+ def initialize(results)
11
+ @path = nil
12
+ @results = results
13
+ @checklist = CheckList::Helpers.system_cmd('ls | grep checklist')
14
+ publish_results
15
+ end
16
+
17
+ private
18
+
19
+ def publish_results
20
+ return create_checklist_folder if @checklist == ''
21
+
22
+ # TODO: Go through all results. If changed then replace.
23
+ file = File.read('./checklist/data.json')
24
+ data_hash = JSON.parse(file)
25
+
26
+ data_hash['results'] = data_hash['results'].reject do |res|
27
+ res['name'] == @results[:name] && res['ref'] == @results[:ref]
28
+ end
29
+
30
+ data_hash['results'].push @results
31
+ CheckList::Helpers.write_json_file(data_hash)
32
+ data_hash
33
+ end
34
+
35
+ def move_build_to_checklist
36
+ @path = CheckList::Config.path
37
+
38
+ return if @path.nil?
39
+
40
+ CheckList::Helpers.system_cmd "cp -r #{@path}/build/ ./checklist/"
41
+ end
42
+
43
+ def create_checklist_folder
44
+ data_hash = { 'results' => [] }
45
+ FileUtils.mkdir_p('checklist')
46
+ move_build_to_checklist
47
+
48
+ data_hash['results'].push @results
49
+ CheckList::Helpers.write_json_file(data_hash)
50
+ data_hash
51
+ end
52
+ end
53
+ end
data/lib/symbolize.rb ADDED
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'exceptions'
4
+
5
+ # creates a symbolized hash
6
+ class Sym
7
+ attr_reader :hash
8
+
9
+ def initialize(hash)
10
+ @hash = hash
11
+ @hash = process_hash(@hash)
12
+ end
13
+
14
+ def process_hash(hash)
15
+ raise CheckList::Exceptions::NotAHash, 'Please pass a valid hash' unless hash.is_a? Hash
16
+
17
+ hash.transform_keys!(&:to_sym)
18
+ keys = hash.keys
19
+ new_hash = {}
20
+
21
+ keys.each do |key|
22
+ new_hash[key] = hash[key]
23
+ new_hash[key] = process_hash(hash[key]) if hash[key].is_a? Hash
24
+ new_hash[key] = process_array(hash[key]) if hash[key].is_a? Array
25
+ end
26
+ new_hash
27
+ end
28
+
29
+ def process_array(array)
30
+ new_array = []
31
+
32
+ array.each do |item|
33
+ new_array.push item unless item.is_a?(Array) || item.is_a?(Hash)
34
+ new_array.push process_array(item) if item.is_a? Array
35
+ new_array.push process_hash(item) if item.is_a? Hash
36
+ end
37
+ new_array
38
+ end
39
+ end
data/lib/update.rb ADDED
@@ -0,0 +1,156 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'helpers'
4
+ require_relative 'config'
5
+ require_relative 'display_results'
6
+ require_relative 'symbolize'
7
+
8
+ module CheckList
9
+ # Class to handle updates
10
+ class Update
11
+ HELP = CheckList::Helpers
12
+
13
+ def initialize(opts, filepath)
14
+ @opts = opts
15
+ @json = filepath.fetch_json('CHECKLIST')
16
+ end
17
+
18
+ def show_lists(type)
19
+ HELP.clear if type.is_a? String
20
+ HELP.log 'Edit Cancelled' if type.is_a? String
21
+ HELP.log 'Lists'
22
+ HELP.log ''
23
+
24
+ @json['results'].each_with_index do |list, index|
25
+ HELP.log "#{index + 1}. #{list['name']} (#{list['ref']})"
26
+ end
27
+
28
+ value = validate_ret_value(HELP.ret_value, @json['results'])
29
+
30
+ return show_list(value, nil) unless value.zero?
31
+
32
+ HELP.clear
33
+ show_lists(type)
34
+ end
35
+
36
+ def check_for_q(value)
37
+ return HELP.good_bye if value.downcase == 'q'
38
+
39
+ value
40
+ end
41
+
42
+ def validate_ret_value(value, arr)
43
+ val = arr.length
44
+ return value.to_i if !value.to_i.zero? && value.to_i <= val
45
+
46
+ return check_for_q(value) if value == 'q'
47
+
48
+ 0
49
+ rescue StandardError
50
+ HELP.log 'Incorrect value'
51
+ 0
52
+ end
53
+
54
+ def show_list(value, type)
55
+ HELP.clear
56
+ HELP.log 'Invalid selection' if type.is_a? String
57
+
58
+ name = @json['results'][value - 1]['name']
59
+ ref = @json['results'][value - 1]['ref']
60
+ @list = @json['results'][value - 1]
61
+ HELP.log "List: #{name} (#{ref})"
62
+ @json['results'][value - 1]['tasks'].each_with_index do |task, index|
63
+ HELP.log "#{index + 1}. #{task['name']} (status: #{HELP.check_status(task['status'])})"
64
+ task['subTasks'].each_with_index do |sub_task, idx|
65
+ HELP.log " #{idx + 1}. #{sub_task['name']} (status: #{HELP.check_status(sub_task['status'])})"
66
+ end
67
+ end
68
+ edit(value)
69
+ rescue StandardError => e
70
+ HELP.log "Error: #{e}"
71
+ HELP.leave
72
+ end
73
+
74
+ def edit(orig_value)
75
+ value = check_for_q(HELP.ret_value)
76
+
77
+ val_arr = nil
78
+ val_arr = value.split(',', -1) if value.match(/^[-,0-9]+$/)
79
+ arr_length = val_arr.length unless val_arr.nil?
80
+
81
+ case arr_length
82
+ when 1
83
+ return show_list(orig_value, 'yes') if val_arr[0].to_i.zero?
84
+
85
+ return show_sub_tasks(val_arr[0].to_i, orig_value)
86
+ when 2
87
+ return show_list(orig_value, 'yes') if val_arr[0].to_i.zero? || val_arr[1].to_i.zero?
88
+
89
+ return edit_sub_task(val_arr[0].to_i, val_arr[1].to_i, orig_value)
90
+ end
91
+ show_list(orig_value, 'yes')
92
+ end
93
+
94
+ def show_sub_tasks(task_idx, orig_value)
95
+ HELP.clear
96
+ task = @list['tasks'][task_idx - 1]
97
+ HELP.log task['name']
98
+ task['subTasks'].each_with_index do |tsk, idx|
99
+ HELP.log " #{idx + 1}. #{tsk['name']} (status: #{HELP.check_status(tsk['status'])})"
100
+ end
101
+ sub_task_idx = check_for_q(HELP.ret_value)
102
+ return show_list(orig_value, 'yes') if sub_task_idx.to_i.zero?
103
+
104
+ edit_sub_task(task_idx, sub_task_idx.to_i, orig_value)
105
+ rescue StandardError
106
+ show_list(orig_value, 'yes')
107
+ end
108
+
109
+ def edit_sub_task(task_idx, sub_task_idx, orig_value)
110
+ HELP.clear
111
+ task = @list['tasks'][task_idx - 1]
112
+ sub_task = task['subTasks'][sub_task_idx - 1]
113
+
114
+ HELP.log "#{sub_task['name']} (status: #{HELP.check_status(sub_task['status'])})"
115
+ HELP.log "Change: (#{HELP.green}yes#{HELP.white}/#{HELP.red}no#{HELP.white})"
116
+
117
+ value = check_for_q(HELP.ret_value)
118
+ yes = "#{HELP.green}y#{HELP.white}"
119
+ no = "#{HELP.red}n#{HELP.white}"
120
+ na = "#{HELP.yellow}na#{HELP.white}"
121
+ HELP.log "Status: (#{yes}/#{no}/#{na})" if verify_edit(value)
122
+ value = check_for_q(HELP.ret_value)
123
+ update_results(value, orig_value, task_idx, sub_task_idx)
124
+ rescue StandardError
125
+ show_list(orig_value, 'yes')
126
+ end
127
+
128
+ def update_results(value, orig_value, task_idx, sub_task_idx)
129
+ list = @json['results'][orig_value - 1]
130
+ task = list['tasks'][task_idx - 1]
131
+ subtask = task['subTasks'][sub_task_idx - 1]
132
+ subtasks = task['subTasks']
133
+ subtask['status'] = value
134
+ subtask['time'] = CheckList::Config.time_now
135
+
136
+ task['status'] = 'y'
137
+ task['time'] = CheckList::Config.time_now
138
+ subtasks.each do |tsk|
139
+ if tsk['status'] == 'n'
140
+ task['status'] = 'n'
141
+ break
142
+ end
143
+ end
144
+
145
+ HELP.write_json_file(@json)
146
+ list = Sym.new(list).hash
147
+ CheckList::DisplayResults.new(list)
148
+ end
149
+
150
+ def verify_edit(value)
151
+ return show_lists('yes') unless value.downcase == 'yes'
152
+
153
+ true
154
+ end
155
+ end
156
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CheckList
4
+ # Checklist Validations
5
+ class Validations
6
+ def self.validate(value, array)
7
+ return 0 if value == 'q'
8
+
9
+ return value.to_i if array && value.to_i < array.length + 1 && !value.to_i.zero?
10
+
11
+ return false unless array
12
+
13
+ nil
14
+ end
15
+
16
+ def self.validate_response(value)
17
+ case value
18
+ when 'y'
19
+ value
20
+ when 'n'
21
+ value
22
+ when 'na'
23
+ value
24
+ when 'q'
25
+ value
26
+ else
27
+ 0
28
+ end
29
+ end
30
+ end
31
+ end
data/lib/view.rb ADDED
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'helpers'
4
+ require_relative 'config'
5
+
6
+ module CheckList
7
+ # Class to build the selection menu
8
+ class View
9
+ def initialize
10
+ open_browser_view
11
+ end
12
+
13
+ private
14
+
15
+ def open_browser_view
16
+ CheckList::Helpers.system_cmd('open ./checklist/index.html')
17
+ end
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: check_list
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Kyle Swaffield
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-12-21 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A cli checklist
14
+ email: kyle@swaff.iu.au
15
+ executables:
16
+ - check-list
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - CHANGELOG.md
21
+ - README.md
22
+ - bin/check-list
23
+ - lib/build/asset-manifest.json
24
+ - lib/build/cross.ico
25
+ - lib/build/data.json
26
+ - lib/build/favicon.ico
27
+ - lib/build/index.html
28
+ - lib/build/list.ico
29
+ - lib/build/manifest.json
30
+ - lib/build/robots.txt
31
+ - lib/build/static/css/main.f784b531.css
32
+ - lib/build/static/css/main.f784b531.css.map
33
+ - lib/build/static/js/787.46b4d4fc.chunk.js
34
+ - lib/build/static/js/787.46b4d4fc.chunk.js.map
35
+ - lib/build/static/js/main.8c659df8.js
36
+ - lib/build/static/js/main.8c659df8.js.LICENSE.txt
37
+ - lib/build/static/js/main.8c659df8.js.map
38
+ - lib/build/static/js/main.8f3bcf6c.js
39
+ - lib/build/static/js/main.8f3bcf6c.js.LICENSE.txt
40
+ - lib/build/static/js/main.8f3bcf6c.js.map
41
+ - lib/build/static/js/main.ba318bd4.js
42
+ - lib/build/static/js/main.ba318bd4.js.LICENSE.txt
43
+ - lib/build/static/js/main.ba318bd4.js.map
44
+ - lib/build/static/js/main.cc14af32.js
45
+ - lib/build/static/js/main.cc14af32.js.LICENSE.txt
46
+ - lib/build/static/js/main.cc14af32.js.map
47
+ - lib/build/tick.ico
48
+ - lib/check_list.rb
49
+ - lib/checklist.json
50
+ - lib/config.rb
51
+ - lib/display_results.rb
52
+ - lib/exceptions.rb
53
+ - lib/handle_file.rb
54
+ - lib/helpers.rb
55
+ - lib/list.rb
56
+ - lib/menu.rb
57
+ - lib/results.rb
58
+ - lib/results_publisher.rb
59
+ - lib/symbolize.rb
60
+ - lib/update.rb
61
+ - lib/validations.rb
62
+ - lib/view.rb
63
+ homepage: https://rubygems.org/gems/check_list
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '2.6'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubygems_version: 3.2.17
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: A
86
+ test_files: []