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
Binary file
data/lib/check_list.rb ADDED
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'optimist'
4
+ require_relative 'menu'
5
+ require_relative 'list'
6
+ require_relative 'view'
7
+ require_relative 'config'
8
+ require_relative 'handle_file'
9
+ require_relative 'exceptions'
10
+ require_relative 'helpers'
11
+ require_relative 'update'
12
+
13
+ # Check-list application
14
+ module CheckList
15
+ # The start method for check-list
16
+ class Start
17
+ attr_reader :opts
18
+
19
+ def initialize
20
+ @opts = set_options
21
+ @filepath = CheckList::HandleFile.new
22
+ handler
23
+ end
24
+
25
+ # rubocop: disable Layout/HeredocIndentation
26
+ # rubocop: disable Naming/HeredocDelimiterNaming
27
+ def set_options
28
+ Optimist.options do
29
+ version "check-list #{CheckList::Config.version} (c) 2022 Kyle Swaffield"
30
+ banner <<~EOS
31
+ Check-List
32
+
33
+ Usage:
34
+ check-list [options] <list name> | <reference name>
35
+ where [options] are:
36
+ EOS
37
+ opt :list, 'checklist name', :type => :string # flag --list, default false
38
+ opt :ref, 'Reference', :type => :string # flag --ref, default false
39
+ opt :view, 'View browser list'
40
+ opt :update, 'Update list'
41
+ end
42
+ end
43
+ # rubocop: enable Layout/HeredocIndentation
44
+ # rubocop: enable Naming/HeredocDelimiterNaming
45
+
46
+ def handler
47
+ if @opts[:update_given]
48
+ update
49
+ elsif @opts[:view_given]
50
+ view
51
+ else
52
+ CheckList::Menu.new(@filepath, @opts)
53
+ end
54
+ rescue CheckList::Exceptions::InvalidOptionError
55
+ CheckList::Helpers.log 'Invalid list option selection'
56
+ end
57
+
58
+ def update
59
+ @update = CheckList::Update.new(@opts, @filepath)
60
+ return update_ref if @opts[:list_given] && @opts[:ref_given]
61
+
62
+ update_list
63
+ end
64
+
65
+ def update_ref
66
+ @update.show_list('', nil)
67
+ end
68
+
69
+ def update_list
70
+ @update.show_lists(nil)
71
+ end
72
+
73
+ def view
74
+ return view_ref if @opts[:list_given] && @opts[:ref_given]
75
+
76
+ view_list
77
+ end
78
+
79
+ def view_ref
80
+ puts 'view ref'
81
+ end
82
+
83
+ def view_list
84
+ CheckList::View.new
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,137 @@
1
+ {
2
+ "lists":[
3
+ {
4
+ "name":"Deveploment",
5
+ "description":"A longer description of the list",
6
+ "tasks": [
7
+ {
8
+ "name":"read requirements",
9
+ "description":"A longer description of the task",
10
+ "subTasks": [
11
+ {
12
+ "name":"Are they reasonable?",
13
+ "description":"A longer description of the sub-task"
14
+ },
15
+ {
16
+ "name":"Can they be met?",
17
+ "description":"A longer description of the sub-task"
18
+ }
19
+ ]
20
+ },
21
+ {
22
+ "name":"Prep Environment",
23
+ "description":"A longer description of the task",
24
+ "subTasks": [
25
+ {
26
+ "name":"Do you have all the credentials?",
27
+ "description":"A longer description of the sub-task"
28
+ },
29
+ {
30
+ "name":"Can you run the current version end-to-end?",
31
+ "description":"A longer description of the sub-task"
32
+ },
33
+ {
34
+ "name":"Does the debugger work?",
35
+ "description":"A longer description of the sub-task"
36
+ }
37
+ ]
38
+ },
39
+ {
40
+ "name":"Start Development",
41
+ "description":"A longer description of the task",
42
+ "subTasks": [
43
+ {
44
+ "name":"Write Code",
45
+ "description":"A longer description of the sub-task"
46
+ },
47
+ {
48
+ "name":"Write Specs",
49
+ "description":"A longer description of the sub-task"
50
+ },
51
+ {
52
+ "name":"Update documentation",
53
+ "description":"A longer description of the sub-task"
54
+ },
55
+ {
56
+ "name":"Prepare code for testing",
57
+ "description":"A longer description of the sub-task"
58
+ }
59
+ ]
60
+ },
61
+ {
62
+ "name":"Run Specs",
63
+ "description":"A longer description of the task",
64
+ "subTasks": [
65
+ {
66
+ "name":"Does linting pass?",
67
+ "description":"A longer description of the sub-task"
68
+ },
69
+ {
70
+ "name":"Do specs pass?",
71
+ "description":"A longer description of the sub-task"
72
+ }
73
+ ]
74
+ }
75
+ ]
76
+ },
77
+ {
78
+ "name":"Code Review",
79
+ "tasks": [
80
+ {
81
+ "name":"Read Alice in wonder land",
82
+ "description":"A longer description of the task",
83
+ "subTasks": [
84
+ {
85
+ "name":"is there a red queen?",
86
+ "description":"A longer description of the sub-task"
87
+ },
88
+ {
89
+ "name":"Where is the cat?",
90
+ "description":"A longer description of the sub-task"
91
+ }
92
+ ]
93
+ },
94
+ {
95
+ "name":"Cards",
96
+ "description":"A longer description of the task",
97
+ "subTasks": [
98
+ {
99
+ "name":"Red Cards?",
100
+ "description":"A longer description of the sub-task"
101
+ },
102
+ {
103
+ "name":"Red queen?",
104
+ "description":"A longer description of the sub-task"
105
+ },
106
+ {
107
+ "name":"done?",
108
+ "description":"A longer description of the sub-task"
109
+ }
110
+ ]
111
+ },
112
+ {
113
+ "name":"Start Review",
114
+ "description":"A longer description of the task",
115
+ "subTasks": [
116
+ {
117
+ "name":"Write Code",
118
+ "description":"A longer description of the sub-task"
119
+ },
120
+ {
121
+ "name":"Write Specs",
122
+ "description":"A longer description of the sub-task"
123
+ },
124
+ {
125
+ "name":"Update documentation",
126
+ "description":"A longer description of the sub-task"
127
+ },
128
+ {
129
+ "name":"Prepare code for testing",
130
+ "description":"A longer description of the sub-task"
131
+ }
132
+ ]
133
+ }
134
+ ]
135
+ }
136
+ ]
137
+ }
data/lib/config.rb ADDED
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CheckList
4
+ # Check-list version number
5
+ class Config
6
+ def self.version
7
+ '1.0.0'
8
+ end
9
+
10
+ def self.default_url
11
+ 'https://raw.githubusercontent.com/swaff-y/check-list/main/lib/checklist.json'
12
+ end
13
+
14
+ def self.env
15
+ 'CHECK_LIST'
16
+ end
17
+
18
+ def self.coverage
19
+ 95
20
+ end
21
+
22
+ def self.time_now
23
+ t = Time.now
24
+ year = t.year
25
+ month = t.month.to_s.rjust(2, '0')
26
+ day = t.day.to_s.rjust(2, '0')
27
+ hr = t.hour.to_s.rjust(2, '0')
28
+ min = t.min.to_s.rjust(2, '0')
29
+ "#{year}-#{month}-#{day} #{hr}:#{min}"
30
+ end
31
+
32
+ def self.path
33
+ ret_path = nil
34
+ $LOAD_PATH.each do |path|
35
+ if path.match(/check_list-/)
36
+ ret_path = path
37
+ break
38
+ end
39
+ end
40
+ ret_path
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CheckList
4
+ # Display the results of a completed checklist
5
+ class DisplayResults
6
+ def initialize(results)
7
+ @path = nil
8
+ @results = results
9
+ display_results
10
+ end
11
+
12
+ private
13
+
14
+ def make_mark(status)
15
+ case status
16
+ when 'y'
17
+ "#{make_color(status)}(/)#{CheckList::Helpers.white}"
18
+ when 'n'
19
+ "#{make_color(status)}(x)#{CheckList::Helpers.white}"
20
+ when 'na'
21
+ "#{make_color(status)}(*)#{CheckList::Helpers.white}"
22
+ end
23
+ end
24
+
25
+ def make_color(status)
26
+ case status
27
+ when 'y'
28
+ CheckList::Helpers.green
29
+ when 'n'
30
+ CheckList::Helpers.red
31
+ when 'na'
32
+ CheckList::Helpers.yellow
33
+ end
34
+ end
35
+
36
+ def display_results
37
+ CheckList::Helpers.clear
38
+ CheckList::Helpers.log "*#{@results[:name]}* Checklist: #{@results[:ref]}"
39
+ CheckList::Helpers.log ''
40
+ @results[:tasks].each_with_index do |task, index|
41
+ CheckList::Helpers.log " #{make_color(task[:status])}#{index + 1}.#{CheckList::Helpers.white} #{task[:name]} #{make_mark(task[:status])} _#{task[:time]}_"
42
+ @results[:tasks][index][:subTasks].each_with_index do |sub_task, idx|
43
+ CheckList::Helpers.log " #{make_color(sub_task[:status])}#{idx + 1}.#{CheckList::Helpers.white} #{sub_task[:name]}#{CheckList::Helpers.white} #{make_mark(sub_task[:status])} _#{sub_task[:time]}_"
44
+ end
45
+ end
46
+ CheckList::Helpers.log ''
47
+ CheckList::Helpers.log "To view results in your browser use 'check-list --view'"
48
+ end
49
+ end
50
+ end
data/lib/exceptions.rb ADDED
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'helpers'
4
+
5
+ module CheckList
6
+ module Exceptions
7
+ # Checklist errors
8
+ class InvalidListError < StandardError
9
+ end
10
+
11
+ # options errors
12
+ class InvalidOptionError < StandardError
13
+ end
14
+
15
+ # options errors
16
+ class NotAHash < StandardError
17
+ end
18
+
19
+ # Coverage errors
20
+ class CoverageError < StandardError
21
+ def initialize
22
+ super
23
+ CheckList::Helpers.log "#{CheckList::Helpers.red}Insufficient Coverage#{CheckList::Helpers.white}"
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'helpers'
4
+ require_relative 'config'
5
+ require 'net/http'
6
+
7
+ module CheckList
8
+ # Displays the keyword/method provided
9
+ class HandleFile
10
+ def initialize
11
+ @default_file = nil
12
+ fetch_default_file
13
+ end
14
+
15
+ def fetch_default_file
16
+ uri = URI.parse(CheckList::Config.default_url)
17
+ @default_file = Net::HTTP.get_response(uri)
18
+ rescue StandardError
19
+ @default_file = nil
20
+ end
21
+
22
+ def fetch_json(env_key)
23
+ url = './checklist/data.json'
24
+ url = ENV.fetch(env_key) if CheckList::Config.env == env_key
25
+ JSON.parse(File.read(url))
26
+ rescue StandardError => e
27
+ if env_key == CheckList::Config.env && !@default_file.nil?
28
+ JSON.parse(@default_file.body)
29
+ else
30
+ CheckList::Helpers.log "Invalid file: #{e}"
31
+ CheckList::Helpers.leave
32
+ end
33
+ end
34
+ end
35
+ end
data/lib/helpers.rb ADDED
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CheckList
4
+ # Class to build the selection menu
5
+ class Helpers
6
+ def self.good_bye
7
+ clear
8
+ log 'Good Bye'
9
+ leave
10
+ end
11
+
12
+ def self.check_status(status)
13
+ case status.downcase
14
+ when 'y'
15
+ "#{green}Complete#{white}"
16
+ when 'n'
17
+ "#{red}Not Complete#{white}"
18
+ when 'na'
19
+ "#{yellow}Not Applicable#{white}"
20
+ end
21
+ end
22
+
23
+ def self.clear
24
+ system 'clear'
25
+ end
26
+
27
+ def self.log(str)
28
+ puts str
29
+ end
30
+
31
+ def self.ret_value
32
+ $stdin.gets.chomp
33
+ end
34
+
35
+ def self.leave
36
+ exit
37
+ end
38
+
39
+ def self.system_cmd(cmd)
40
+ `#{cmd}`
41
+ end
42
+
43
+ def self.write_json_file(data_hash)
44
+ File.write('./checklist/data.json', JSON.pretty_generate(data_hash))
45
+ end
46
+
47
+ def self.bg_red
48
+ "\x1b[41m"
49
+ end
50
+
51
+ def self.bg_green
52
+ "\x1b[42m"
53
+ end
54
+
55
+ def self.bg_yellow
56
+ "\x1b[43m"
57
+ end
58
+
59
+ def self.bg_white
60
+ "\x1b[47m"
61
+ end
62
+
63
+ def self.red
64
+ "\x1b[31m"
65
+ end
66
+
67
+ def self.green
68
+ "\x1b[32m"
69
+ end
70
+
71
+ def self.yellow
72
+ "\x1b[33m"
73
+ end
74
+
75
+ def self.white
76
+ "\x1b[37m"
77
+ end
78
+ end
79
+ end
data/lib/list.rb ADDED
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require_relative 'config'
5
+ require_relative 'helpers'
6
+ require_relative 'handle_file'
7
+
8
+ module CheckList
9
+ # Class to build the selection menu
10
+ class List
11
+ def initialize(filepath)
12
+ CheckList::Helpers.clear
13
+ @json = filepath.fetch_json
14
+ show_list
15
+ end
16
+
17
+ def show_list
18
+ CheckList::Helpers.log 'list'
19
+ end
20
+ end
21
+ end
data/lib/menu.rb ADDED
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require_relative 'config'
5
+ require_relative 'helpers'
6
+ require_relative 'handle_file'
7
+ require_relative 'exceptions'
8
+ require_relative 'results'
9
+ require_relative 'validations'
10
+
11
+ module CheckList
12
+ # Class to build the selection menu
13
+ class Menu
14
+ attr_reader :results
15
+
16
+ def initialize(filepath, opts)
17
+ @opts = opts
18
+ @list = nil
19
+ @task_idx = nil
20
+ @sub_task_idx = nil
21
+ @results = CheckList::Results.new(@opts)
22
+ @json = filepath.fetch_json(CheckList::Config.env)
23
+ show_menu
24
+ end
25
+
26
+ def show_menu
27
+ list_array = @json['lists']
28
+ CheckList::Helpers.log 'Checklists'
29
+
30
+ list_array.each_with_index do |list, index|
31
+ CheckList::Helpers.log "#{index + 1}. #{list['name']}"
32
+ end
33
+ value = CheckList::Validations.validate(CheckList::Helpers.ret_value, list_array)
34
+ return CheckList::Helpers.good_bye if !value || value.zero?
35
+
36
+ @list = get_list(value) unless value.nil?
37
+ return show_tasks unless @list.nil?
38
+
39
+ rec_show_menu
40
+ end
41
+
42
+ def rec_show_menu
43
+ show_menu
44
+ end
45
+
46
+ def show_tasks
47
+ @task_idx = 0 if @task_idx.nil?
48
+
49
+ return @results.process_results if @task_idx == @list['tasks'].length
50
+
51
+ show_sub_tasks
52
+ end
53
+
54
+ def show_sub_tasks
55
+ # This gaurd clause is neccecary to protect an incorrect value being entered.
56
+ # This causes an extra recrsive call to show_sub_tasks
57
+ return if @task_idx == @list['tasks'].length
58
+
59
+ CheckList::Helpers.clear
60
+ CheckList::Helpers.log "#{@task_idx + 1}. #{@list['tasks'][@task_idx]['name']}"
61
+
62
+ @sub_task_idx = 0 if @sub_task_idx.nil?
63
+ task = @list['tasks'][@task_idx]
64
+ sub_tasks = @list['tasks'][@task_idx]['subTasks']
65
+
66
+ CheckList::Helpers.log " #{@sub_task_idx + 1}. #{sub_tasks[@sub_task_idx]['name']} #{y}/#{n}/#{na}"
67
+
68
+ @sub_task_idx += 1
69
+ value = CheckList::Validations.validate_response(CheckList::Helpers.ret_value)
70
+ return CheckList::Helpers.good_bye if value == 'q'
71
+
72
+ # rubocop:disable Style/NumericPredicate:
73
+ if value == 0
74
+ @sub_task_idx -= 1
75
+ return rec_show_sub_tasks
76
+ end
77
+ # rubocop:enable Style/NumericPredicate:
78
+
79
+ @results.process_value(@list, value, task, sub_tasks[@sub_task_idx - 1])
80
+ return rec_show_sub_tasks if @sub_task_idx < sub_tasks.length
81
+
82
+ @sub_task_idx = 0
83
+ @task_idx += 1
84
+ show_tasks
85
+ end
86
+
87
+ def y
88
+ "#{CheckList::Helpers.green}y#{CheckList::Helpers.white}"
89
+ end
90
+
91
+ def n
92
+ "#{CheckList::Helpers.red}n#{CheckList::Helpers.white}"
93
+ end
94
+
95
+ def na
96
+ "#{CheckList::Helpers.yellow}na#{CheckList::Helpers.white}"
97
+ end
98
+
99
+ def rec_show_sub_tasks
100
+ show_sub_tasks
101
+ end
102
+
103
+ def get_list(value)
104
+ @json['lists'][value - 1]
105
+ end
106
+ end
107
+ end