worker_tools 0.1.2 → 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.
- checksums.yaml +5 -5
- data/.travis.yml +2 -1
- data/CHANGELOG.md +48 -0
- data/README.md +358 -20
- data/lib/worker_tools/basics.rb +27 -11
- data/lib/worker_tools/benchmark.rb +15 -0
- data/lib/worker_tools/counters.rb +40 -0
- data/lib/worker_tools/csv_input.rb +13 -4
- data/lib/worker_tools/csv_output.rb +19 -33
- data/lib/worker_tools/errors.rb +10 -0
- data/lib/worker_tools/recorder.rb +20 -12
- data/lib/worker_tools/slack_error_notifier.rb +6 -2
- data/lib/worker_tools/utils/hash_with_indifferent_access_type.rb +9 -0
- data/lib/worker_tools/utils/serialized_array_type.rb +19 -0
- data/lib/worker_tools/version.rb +1 -1
- data/lib/worker_tools/xlsx_input.rb +14 -4
- data/lib/worker_tools/xlsx_output.rb +51 -43
- data/lib/worker_tools.rb +1 -1
- data/worker_tools.gemspec +3 -3
- metadata +15 -25
- data/lib/worker_tools/rocketchat_error_notifier.rb +0 -68
|
@@ -54,6 +54,7 @@ module WorkerTools
|
|
|
54
54
|
def csv_input_columns_check(csv_rows_enum)
|
|
55
55
|
# override and return true if you do not want this check to be performed
|
|
56
56
|
return csv_input_columns_array_check(csv_rows_enum) if csv_input_columns.is_a?(Array)
|
|
57
|
+
|
|
57
58
|
csv_input_columns_hash_check(csv_rows_enum)
|
|
58
59
|
end
|
|
59
60
|
|
|
@@ -61,7 +62,9 @@ module WorkerTools
|
|
|
61
62
|
expected_columns_length = csv_input_columns.length
|
|
62
63
|
actual_columns_length = csv_rows_enum.first.length
|
|
63
64
|
return if expected_columns_length == actual_columns_length
|
|
64
|
-
|
|
65
|
+
|
|
66
|
+
msg = "The number of columns (#{actual_columns_length}) is not the expected (#{expected_columns_length})"
|
|
67
|
+
raise Errors::WrongNumberOfColumns, msg
|
|
65
68
|
end
|
|
66
69
|
|
|
67
70
|
def csv_input_columns_hash_check(csv_rows_enum)
|
|
@@ -73,7 +76,9 @@ module WorkerTools
|
|
|
73
76
|
|
|
74
77
|
def csv_input_columns_hash_check_duplicates(names)
|
|
75
78
|
dups = names.group_by(&:itself).select { |_, v| v.count > 1 }.keys
|
|
76
|
-
|
|
79
|
+
return unless dups.present?
|
|
80
|
+
|
|
81
|
+
raise Errors::DuplicatedColumns, "The file contains duplicated columns: #{dups}"
|
|
77
82
|
end
|
|
78
83
|
|
|
79
84
|
def csv_input_columns_hash_check_missing(actual_names, expected_names)
|
|
@@ -81,7 +86,7 @@ module WorkerTools
|
|
|
81
86
|
matchable = name.is_a?(String) ? csv_input_header_normalized(name) : name
|
|
82
87
|
actual_names.any? { |n| case n when matchable then true end } # rubocop does not like ===
|
|
83
88
|
end
|
|
84
|
-
raise "Some columns are missing: #{missing}" unless missing.empty?
|
|
89
|
+
raise Errors::MissingColumns, "Some columns are missing: #{missing}" unless missing.empty?
|
|
85
90
|
end
|
|
86
91
|
|
|
87
92
|
def csv_input_csv_options
|
|
@@ -105,6 +110,7 @@ module WorkerTools
|
|
|
105
110
|
# => { tenant: 1, area: 0}
|
|
106
111
|
def csv_input_mapping_order(header_names)
|
|
107
112
|
return csv_input_columns.map.with_index { |n, i| [n, i] }.to_h if csv_input_columns.is_a?(Array)
|
|
113
|
+
|
|
108
114
|
csv_input_mapping_order_for_hash(header_names)
|
|
109
115
|
end
|
|
110
116
|
|
|
@@ -115,6 +121,7 @@ module WorkerTools
|
|
|
115
121
|
h[k] = filtered_column_names.index { |n| case n when matchable then true end }
|
|
116
122
|
end
|
|
117
123
|
return mapping unless csv_input_include_other_columns
|
|
124
|
+
|
|
118
125
|
csv_input_mapping_order_with_other_columns(mapping, filtered_column_names)
|
|
119
126
|
end
|
|
120
127
|
|
|
@@ -131,7 +138,7 @@ module WorkerTools
|
|
|
131
138
|
end
|
|
132
139
|
|
|
133
140
|
def csv_rows_enum
|
|
134
|
-
@csv_rows_enum ||= CSV.foreach(csv_input_file_path, csv_input_csv_options)
|
|
141
|
+
@csv_rows_enum ||= CSV.foreach(csv_input_file_path, **csv_input_csv_options)
|
|
135
142
|
end
|
|
136
143
|
|
|
137
144
|
def csv_input_headers_present
|
|
@@ -168,12 +175,14 @@ module WorkerTools
|
|
|
168
175
|
|
|
169
176
|
@rows_enum.with_index.each do |values, index|
|
|
170
177
|
next if index.zero? && @headers_present
|
|
178
|
+
|
|
171
179
|
yield values_to_row(values)
|
|
172
180
|
end
|
|
173
181
|
end
|
|
174
182
|
|
|
175
183
|
def values_to_row(values)
|
|
176
184
|
return values_to_row_according_to_mapping(values) if @mapping_order
|
|
185
|
+
|
|
177
186
|
values_to_row_according_to_position(values)
|
|
178
187
|
end
|
|
179
188
|
|
|
@@ -2,13 +2,6 @@ require 'csv'
|
|
|
2
2
|
|
|
3
3
|
module WorkerTools
|
|
4
4
|
module CsvOutput
|
|
5
|
-
# if defined, this file will be written to this destination (regardless
|
|
6
|
-
# of whether the model saves the file as well)
|
|
7
|
-
def csv_output_target
|
|
8
|
-
# Ex: Rails.root.join('shared', 'foo', 'bar.csv')
|
|
9
|
-
false
|
|
10
|
-
end
|
|
11
|
-
|
|
12
5
|
def csv_output_entries
|
|
13
6
|
raise "csv_output_entries has to be defined in #{self}"
|
|
14
7
|
end
|
|
@@ -27,33 +20,18 @@ module WorkerTools
|
|
|
27
20
|
raise "csv_output_column_headers has to be defined in #{self}"
|
|
28
21
|
end
|
|
29
22
|
|
|
30
|
-
# rubocop:disable Lint/UnusedMethodArgument
|
|
31
23
|
def csv_output_row_values(entry)
|
|
32
|
-
|
|
33
|
-
# {
|
|
34
|
-
# foo: entry.foo,
|
|
35
|
-
# bar: entry.bar
|
|
36
|
-
# }.values_at(*csv_output_column_headers.keys)
|
|
37
|
-
raise "csv_output_row_values has to be defined in #{self}"
|
|
38
|
-
end
|
|
39
|
-
# rubocop:enable Lint/UnusedMethodArgument
|
|
40
|
-
|
|
41
|
-
def cvs_output_target_folder
|
|
42
|
-
File.dirname(csv_output_target)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def csv_output_target_file_name
|
|
46
|
-
File.basename(csv_output_target)
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def csv_ouput_ensure_target_folder
|
|
50
|
-
FileUtils.mkdir_p(cvs_output_target_folder) unless File.directory?(cvs_output_target_folder)
|
|
24
|
+
entry.values_at(*csv_output_column_headers.keys)
|
|
51
25
|
end
|
|
52
26
|
|
|
53
27
|
def csv_output_tmp_file
|
|
54
28
|
@csv_output_tmp_file ||= Tempfile.new(['output', '.csv'])
|
|
55
29
|
end
|
|
56
30
|
|
|
31
|
+
def csv_output_file_name
|
|
32
|
+
"#{model_kind}.csv"
|
|
33
|
+
end
|
|
34
|
+
|
|
57
35
|
def csv_output_col_sep
|
|
58
36
|
';'
|
|
59
37
|
end
|
|
@@ -62,21 +40,29 @@ module WorkerTools
|
|
|
62
40
|
Encoding::UTF_8
|
|
63
41
|
end
|
|
64
42
|
|
|
43
|
+
def csv_output_write_mode
|
|
44
|
+
'wb'
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def csv_output_csv_options
|
|
48
|
+
{ col_sep: csv_output_col_sep, encoding: csv_output_encoding }
|
|
49
|
+
end
|
|
50
|
+
|
|
65
51
|
def csv_output_insert_headers(csv)
|
|
66
52
|
csv << csv_output_column_headers.values if csv_output_column_headers
|
|
67
53
|
end
|
|
68
54
|
|
|
55
|
+
def csv_output_add_attachment
|
|
56
|
+
model.add_attachment(csv_output_tmp_file, file_name: csv_output_file_name, content_type: 'text/csv')
|
|
57
|
+
end
|
|
58
|
+
|
|
69
59
|
def csv_output_write_file
|
|
70
|
-
CSV.open(csv_output_tmp_file,
|
|
60
|
+
CSV.open(csv_output_tmp_file, csv_output_write_mode, **csv_output_csv_options) do |csv|
|
|
71
61
|
csv_output_insert_headers(csv)
|
|
72
62
|
csv_output_entries.each { |entry| csv << csv_output_row_values(entry) }
|
|
73
63
|
end
|
|
74
|
-
csv_output_write_target if csv_output_target
|
|
75
|
-
end
|
|
76
64
|
|
|
77
|
-
|
|
78
|
-
csv_ouput_ensure_target_folder
|
|
79
|
-
FileUtils.cp(csv_output_tmp_file.path, csv_output_target)
|
|
65
|
+
csv_output_add_attachment
|
|
80
66
|
end
|
|
81
67
|
end
|
|
82
68
|
end
|
|
@@ -23,34 +23,42 @@ module WorkerTools
|
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def record_fail(error)
|
|
26
|
-
record "ID #{model.id} - Error"
|
|
27
26
|
record(error, :error)
|
|
28
|
-
model.information = information
|
|
29
27
|
model.save!(validate: false)
|
|
30
28
|
end
|
|
31
29
|
|
|
32
|
-
def add_log(message, level =
|
|
33
|
-
|
|
30
|
+
def add_log(message, level = nil)
|
|
31
|
+
attrs = default_message_attrs(message, level)
|
|
32
|
+
logger.public_send(attrs[:level], format_message(attrs[:message]))
|
|
34
33
|
end
|
|
35
34
|
|
|
36
|
-
def
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
def add_note(message, level = nil)
|
|
36
|
+
attrs = default_message_attrs(message, level)
|
|
37
|
+
model.notes.push(level: attrs[:level], message: attrs[:message])
|
|
39
38
|
end
|
|
40
39
|
|
|
41
40
|
def record(message, level = :info)
|
|
42
41
|
add_log(message, level)
|
|
43
|
-
|
|
42
|
+
add_note(message, level)
|
|
44
43
|
end
|
|
45
44
|
|
|
46
|
-
def
|
|
45
|
+
def level_from_message_type(message)
|
|
46
|
+
return :error if message.is_a?(Exception)
|
|
47
|
+
|
|
48
|
+
:info
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def format_message(message)
|
|
47
52
|
return error_to_text(message, log_error_trace_lines) if message.is_a?(Exception)
|
|
53
|
+
|
|
48
54
|
message
|
|
49
55
|
end
|
|
50
56
|
|
|
51
|
-
def
|
|
52
|
-
|
|
53
|
-
|
|
57
|
+
def default_message_attrs(message, level)
|
|
58
|
+
{
|
|
59
|
+
message: format_message(message),
|
|
60
|
+
level: level || level_from_message_type(message)
|
|
61
|
+
}
|
|
54
62
|
end
|
|
55
63
|
|
|
56
64
|
def logger
|
|
@@ -5,7 +5,7 @@ module WorkerTools
|
|
|
5
5
|
def with_wrapper_slack_error_notifier(&block)
|
|
6
6
|
block.yield
|
|
7
7
|
rescue StandardError => e
|
|
8
|
-
slack_error_notify(e) if slack_error_notifier_enabled
|
|
8
|
+
slack_error_notify(e) if slack_error_notifier_enabled && slack_error_notifiable?(e)
|
|
9
9
|
raise
|
|
10
10
|
end
|
|
11
11
|
|
|
@@ -13,6 +13,10 @@ module WorkerTools
|
|
|
13
13
|
Rails.env.production?
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
+
def slack_error_notifiable?(error)
|
|
17
|
+
error.is_a?(StandardError)
|
|
18
|
+
end
|
|
19
|
+
|
|
16
20
|
def slack_error_notifier_emoji
|
|
17
21
|
':red_circle:'
|
|
18
22
|
end
|
|
@@ -83,7 +87,7 @@ module WorkerTools
|
|
|
83
87
|
|
|
84
88
|
def slack_error_notifier_attachments_fields
|
|
85
89
|
[
|
|
86
|
-
{ title: 'Application', value: Rails.application.class.
|
|
90
|
+
{ title: 'Application', value: Rails.application.class.module_parent_name, short: true },
|
|
87
91
|
{ title: 'Environment', value: Rails.env, short: true }
|
|
88
92
|
]
|
|
89
93
|
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module WorkerTools
|
|
2
|
+
module Utils
|
|
3
|
+
class SerializedArrayType < ActiveRecord::Type::Json
|
|
4
|
+
def initialize(type: nil)
|
|
5
|
+
@type = type
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def deserialize(value)
|
|
9
|
+
super(value)&.map { |d| @type.deserialize(d) }
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def serialize(value)
|
|
13
|
+
raise 'not an array' unless value.is_a?(Array)
|
|
14
|
+
|
|
15
|
+
super value
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
data/lib/worker_tools/version.rb
CHANGED
|
@@ -47,7 +47,9 @@ module WorkerTools
|
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
def xlsx_input_header_normalized(name)
|
|
50
|
-
|
|
50
|
+
# some elements return obj.to_s => nil
|
|
51
|
+
# for example [#<Roo::Excelx::Cell::Empty:0x0000000af8d4c8 ... @value=nil>]
|
|
52
|
+
name&.to_s&.strip&.downcase || ''
|
|
51
53
|
end
|
|
52
54
|
|
|
53
55
|
# Allows for some basic cleanup of the values, such as applying strip to
|
|
@@ -59,6 +61,7 @@ module WorkerTools
|
|
|
59
61
|
def xlsx_input_columns_check(xlsx_rows_enum)
|
|
60
62
|
# override and return true if you do not want this check to be performed
|
|
61
63
|
return xlsx_input_columns_array_check(xlsx_rows_enum) if xlsx_input_columns.is_a?(Array)
|
|
64
|
+
|
|
62
65
|
xlsx_input_columns_hash_check(xlsx_rows_enum)
|
|
63
66
|
end
|
|
64
67
|
|
|
@@ -66,7 +69,9 @@ module WorkerTools
|
|
|
66
69
|
expected_columns_length = xlsx_input_columns.length
|
|
67
70
|
actual_columns_length = xlsx_rows_enum.first.length
|
|
68
71
|
return if expected_columns_length == actual_columns_length
|
|
69
|
-
|
|
72
|
+
|
|
73
|
+
msg = "The number of columns (#{actual_columns_length}) is not the expected (#{expected_columns_length})"
|
|
74
|
+
raise Errors::WrongNumberOfColumns, msg
|
|
70
75
|
end
|
|
71
76
|
|
|
72
77
|
def xlsx_input_columns_hash_check(xlsx_rows_enum)
|
|
@@ -78,7 +83,9 @@ module WorkerTools
|
|
|
78
83
|
|
|
79
84
|
def xlsx_input_columns_hash_check_duplicates(names)
|
|
80
85
|
dups = names.group_by(&:itself).select { |_, v| v.count > 1 }.keys
|
|
81
|
-
|
|
86
|
+
return unless dups.present?
|
|
87
|
+
|
|
88
|
+
raise Errors::DuplicatedColumns, "The file contains duplicated columns: #{dups}"
|
|
82
89
|
end
|
|
83
90
|
|
|
84
91
|
def xlsx_input_columns_hash_check_missing(actual_names, expected_names)
|
|
@@ -86,7 +93,7 @@ module WorkerTools
|
|
|
86
93
|
matchable = name.is_a?(String) ? xlsx_input_header_normalized(name) : name
|
|
87
94
|
actual_names.any? { |n| case n when matchable then true end } # rubocop does not like ===
|
|
88
95
|
end
|
|
89
|
-
raise "Some columns are missing: #{missing}" unless missing.empty?
|
|
96
|
+
raise Errors::MissingColumns, "Some columns are missing: #{missing}" unless missing.empty?
|
|
90
97
|
end
|
|
91
98
|
|
|
92
99
|
# Compares the first row (header names) with the xlsx_input_columns hash to find
|
|
@@ -97,6 +104,7 @@ module WorkerTools
|
|
|
97
104
|
# => { tenant: 1, area: 0}
|
|
98
105
|
def xlsx_input_mapping_order(header_names)
|
|
99
106
|
return xlsx_input_columns.map.with_index { |n, i| [n, i] }.to_h if xlsx_input_columns.is_a?(Array)
|
|
107
|
+
|
|
100
108
|
xlsx_input_mapping_order_for_hash(header_names)
|
|
101
109
|
end
|
|
102
110
|
|
|
@@ -107,6 +115,7 @@ module WorkerTools
|
|
|
107
115
|
h[k] = filtered_column_names.index { |n| case n when matchable then true end }
|
|
108
116
|
end
|
|
109
117
|
return mapping unless xlsx_input_include_other_columns
|
|
118
|
+
|
|
110
119
|
xlsx_input_mapping_order_with_other_columns(mapping, filtered_column_names)
|
|
111
120
|
end
|
|
112
121
|
|
|
@@ -155,6 +164,7 @@ module WorkerTools
|
|
|
155
164
|
|
|
156
165
|
@rows_enum.with_index.each do |values, index|
|
|
157
166
|
next if index.zero? # headers
|
|
167
|
+
|
|
158
168
|
yield values_to_row(values)
|
|
159
169
|
end
|
|
160
170
|
end
|
|
@@ -1,26 +1,8 @@
|
|
|
1
1
|
require 'rubyXL'
|
|
2
2
|
module WorkerTools
|
|
3
3
|
module XlsxOutput
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
def xlsx_output_target
|
|
7
|
-
# Ex: Rails.root.join('shared', 'foo', 'bar.xlsx')
|
|
8
|
-
raise "xlsx_output_target has to be defined in #{self}"
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def xlsx_output_content
|
|
12
|
-
{
|
|
13
|
-
sheet1: {
|
|
14
|
-
label: 'Sheet 1',
|
|
15
|
-
headers: xlsx_output_column_headers,
|
|
16
|
-
rows: xlsx_output_values,
|
|
17
|
-
column_style: xlsx_output_column_format
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def xlsx_output_values
|
|
23
|
-
raise "xlsx_output_values has to be defined in #{self}"
|
|
4
|
+
def xlsx_output_entries
|
|
5
|
+
raise "xlsx_output_entries has to be defined in #{self}"
|
|
24
6
|
end
|
|
25
7
|
|
|
26
8
|
def xlsx_output_column_headers
|
|
@@ -37,6 +19,21 @@ module WorkerTools
|
|
|
37
19
|
raise "xlsx_output_column_headers has to be defined in #{self}"
|
|
38
20
|
end
|
|
39
21
|
|
|
22
|
+
def xlsx_output_content
|
|
23
|
+
{
|
|
24
|
+
sheet1: {
|
|
25
|
+
label: 'Sheet 1',
|
|
26
|
+
headers: xlsx_output_column_headers,
|
|
27
|
+
rows: xlsx_output_entries.lazy.map { |entry| xlsx_output_row_values(entry) },
|
|
28
|
+
column_style: xlsx_output_column_format
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def xlsx_output_row_values(entry)
|
|
34
|
+
entry.values_at(*xlsx_output_column_headers.keys)
|
|
35
|
+
end
|
|
36
|
+
|
|
40
37
|
def xlsx_output_column_format
|
|
41
38
|
# These columns are used to set the headers, also
|
|
42
39
|
# to set the row values depending on your implementation.
|
|
@@ -51,16 +48,9 @@ module WorkerTools
|
|
|
51
48
|
{}
|
|
52
49
|
end
|
|
53
50
|
|
|
54
|
-
def
|
|
55
|
-
@xlsx_output_target_folder ||= File.dirname(xlsx_output_target)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def xlsx_ensure_output_target_folder
|
|
59
|
-
FileUtils.mkdir_p(xlsx_output_target_folder) unless File.directory?(xlsx_output_target_folder)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def xlsx_insert_headers(spreadsheet, headers)
|
|
51
|
+
def xlsx_output_insert_headers(spreadsheet, headers)
|
|
63
52
|
return unless headers
|
|
53
|
+
|
|
64
54
|
iterator =
|
|
65
55
|
if headers.is_a? Hash
|
|
66
56
|
headers.values
|
|
@@ -72,53 +62,71 @@ module WorkerTools
|
|
|
72
62
|
end
|
|
73
63
|
end
|
|
74
64
|
|
|
75
|
-
def
|
|
65
|
+
def xlsx_output_insert_rows(spreadsheet, rows, headers)
|
|
76
66
|
rows.each_with_index do |row, row_index|
|
|
77
|
-
|
|
67
|
+
xlsx_output_iterators(row, headers).each_with_index do |value, col_index|
|
|
78
68
|
spreadsheet.add_cell(row_index + 1, col_index, value.to_s)
|
|
79
69
|
end
|
|
80
70
|
end
|
|
81
71
|
end
|
|
82
72
|
|
|
83
|
-
def
|
|
73
|
+
def xlsx_output_iterators(iterable, compare_hash = nil)
|
|
84
74
|
if iterable.is_a? Hash
|
|
85
75
|
raise 'parameter compare_hash should be a hash, too.' if compare_hash.nil? || !compare_hash.is_a?(Hash)
|
|
76
|
+
|
|
86
77
|
iterable.values_at(*compare_hash.keys)
|
|
87
78
|
else
|
|
88
79
|
iterable
|
|
89
80
|
end
|
|
90
81
|
end
|
|
91
82
|
|
|
92
|
-
def
|
|
83
|
+
def xlsx_output_style_columns(spreadsheet, styles, headers)
|
|
93
84
|
return false unless headers
|
|
94
85
|
|
|
95
|
-
|
|
86
|
+
xlsx_output_iterators(styles, headers).each_with_index do |format, index|
|
|
96
87
|
next unless format
|
|
88
|
+
|
|
97
89
|
spreadsheet.change_column_width(index, format[:width])
|
|
98
90
|
spreadsheet.change_text_wrap(index, format[:text_wrap])
|
|
99
91
|
end
|
|
100
92
|
true
|
|
101
93
|
end
|
|
102
94
|
|
|
103
|
-
def
|
|
95
|
+
def xlsx_output_tmp_file
|
|
96
|
+
@xlsx_output_tmp_file ||= Tempfile.new(['output', '.xlsx'])
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def xlsx_output_file_name
|
|
100
|
+
"#{model_kind}.xlsx"
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def xlsx_output_add_attachment
|
|
104
|
+
model.add_attachment(
|
|
105
|
+
xlsx_output_tmp_file,
|
|
106
|
+
file_name: xlsx_output_file_name,
|
|
107
|
+
content_type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
108
|
+
)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def xlsx_output_write_sheet(workbook, sheet_content, index)
|
|
104
112
|
sheet = workbook.worksheets[index]
|
|
105
113
|
sheet = workbook.add_worksheet(sheet_content[:label]) if sheet.nil?
|
|
106
114
|
|
|
107
115
|
sheet.sheet_name = sheet_content[:label]
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
116
|
+
xlsx_output_style_columns(sheet, sheet_content[:column_style], sheet_content[:headers])
|
|
117
|
+
xlsx_output_insert_headers(sheet, sheet_content[:headers])
|
|
118
|
+
xlsx_output_insert_rows(sheet, sheet_content[:rows], sheet_content[:headers])
|
|
111
119
|
end
|
|
112
120
|
|
|
113
|
-
def
|
|
114
|
-
xlsx_ensure_output_target_folder
|
|
115
|
-
|
|
121
|
+
def xlsx_output_write_file
|
|
116
122
|
book = RubyXL::Workbook.new
|
|
117
123
|
xlsx_output_content.each_with_index do |(_, object), index|
|
|
118
|
-
|
|
124
|
+
xlsx_output_write_sheet(book, object, index)
|
|
119
125
|
end
|
|
120
126
|
|
|
121
|
-
book.write
|
|
127
|
+
book.write xlsx_output_tmp_file
|
|
128
|
+
|
|
129
|
+
xlsx_output_add_attachment
|
|
122
130
|
end
|
|
123
131
|
end
|
|
124
132
|
end
|
data/lib/worker_tools.rb
CHANGED
data/worker_tools.gemspec
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
lib = File.expand_path('
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
3
|
require 'worker_tools/version'
|
|
4
4
|
|
|
@@ -16,6 +16,7 @@ Gem::Specification.new do |spec|
|
|
|
16
16
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the "allowed_push_host"
|
|
17
17
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
|
18
18
|
raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.' unless spec.respond_to?(:metadata)
|
|
19
|
+
|
|
19
20
|
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
|
20
21
|
|
|
21
22
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
@@ -26,7 +27,6 @@ Gem::Specification.new do |spec|
|
|
|
26
27
|
spec.require_paths = ['lib']
|
|
27
28
|
|
|
28
29
|
spec.add_dependency 'activesupport'
|
|
29
|
-
spec.add_dependency 'rocketchat-notifier', '>= 0.1.2'
|
|
30
30
|
spec.add_dependency 'roo'
|
|
31
31
|
spec.add_dependency 'rubyXL'
|
|
32
32
|
spec.add_dependency 'slack-notifier'
|
|
@@ -39,7 +39,7 @@ Gem::Specification.new do |spec|
|
|
|
39
39
|
spec.add_development_dependency 'mocha'
|
|
40
40
|
spec.add_development_dependency 'pry'
|
|
41
41
|
spec.add_development_dependency 'rake'
|
|
42
|
-
spec.add_development_dependency 'rubocop', '0.
|
|
42
|
+
spec.add_development_dependency 'rubocop', '0.71.0'
|
|
43
43
|
spec.add_development_dependency 'simplecov'
|
|
44
44
|
spec.add_development_dependency 'sqlite3'
|
|
45
45
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: worker_tools
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- fsainz
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2022-06-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -24,20 +24,6 @@ dependencies:
|
|
|
24
24
|
- - ">="
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: '0'
|
|
27
|
-
- !ruby/object:Gem::Dependency
|
|
28
|
-
name: rocketchat-notifier
|
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
|
30
|
-
requirements:
|
|
31
|
-
- - ">="
|
|
32
|
-
- !ruby/object:Gem::Version
|
|
33
|
-
version: 0.1.2
|
|
34
|
-
type: :runtime
|
|
35
|
-
prerelease: false
|
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
-
requirements:
|
|
38
|
-
- - ">="
|
|
39
|
-
- !ruby/object:Gem::Version
|
|
40
|
-
version: 0.1.2
|
|
41
27
|
- !ruby/object:Gem::Dependency
|
|
42
28
|
name: roo
|
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -198,14 +184,14 @@ dependencies:
|
|
|
198
184
|
requirements:
|
|
199
185
|
- - '='
|
|
200
186
|
- !ruby/object:Gem::Version
|
|
201
|
-
version: 0.
|
|
187
|
+
version: 0.71.0
|
|
202
188
|
type: :development
|
|
203
189
|
prerelease: false
|
|
204
190
|
version_requirements: !ruby/object:Gem::Requirement
|
|
205
191
|
requirements:
|
|
206
192
|
- - '='
|
|
207
193
|
- !ruby/object:Gem::Version
|
|
208
|
-
version: 0.
|
|
194
|
+
version: 0.71.0
|
|
209
195
|
- !ruby/object:Gem::Dependency
|
|
210
196
|
name: simplecov
|
|
211
197
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -234,7 +220,7 @@ dependencies:
|
|
|
234
220
|
- - ">="
|
|
235
221
|
- !ruby/object:Gem::Version
|
|
236
222
|
version: '0'
|
|
237
|
-
description:
|
|
223
|
+
description:
|
|
238
224
|
email:
|
|
239
225
|
- fernando.sainz@i22.de
|
|
240
226
|
executables: []
|
|
@@ -244,6 +230,7 @@ files:
|
|
|
244
230
|
- ".gitignore"
|
|
245
231
|
- ".rubocop.yml"
|
|
246
232
|
- ".travis.yml"
|
|
233
|
+
- CHANGELOG.md
|
|
247
234
|
- Gemfile
|
|
248
235
|
- LICENSE
|
|
249
236
|
- README.md
|
|
@@ -252,11 +239,15 @@ files:
|
|
|
252
239
|
- bin/setup
|
|
253
240
|
- lib/worker_tools.rb
|
|
254
241
|
- lib/worker_tools/basics.rb
|
|
242
|
+
- lib/worker_tools/benchmark.rb
|
|
243
|
+
- lib/worker_tools/counters.rb
|
|
255
244
|
- lib/worker_tools/csv_input.rb
|
|
256
245
|
- lib/worker_tools/csv_output.rb
|
|
246
|
+
- lib/worker_tools/errors.rb
|
|
257
247
|
- lib/worker_tools/recorder.rb
|
|
258
|
-
- lib/worker_tools/rocketchat_error_notifier.rb
|
|
259
248
|
- lib/worker_tools/slack_error_notifier.rb
|
|
249
|
+
- lib/worker_tools/utils/hash_with_indifferent_access_type.rb
|
|
250
|
+
- lib/worker_tools/utils/serialized_array_type.rb
|
|
260
251
|
- lib/worker_tools/version.rb
|
|
261
252
|
- lib/worker_tools/xlsx_input.rb
|
|
262
253
|
- lib/worker_tools/xlsx_output.rb
|
|
@@ -266,7 +257,7 @@ licenses:
|
|
|
266
257
|
- MIT
|
|
267
258
|
metadata:
|
|
268
259
|
allowed_push_host: https://rubygems.org
|
|
269
|
-
post_install_message:
|
|
260
|
+
post_install_message:
|
|
270
261
|
rdoc_options: []
|
|
271
262
|
require_paths:
|
|
272
263
|
- lib
|
|
@@ -281,9 +272,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
281
272
|
- !ruby/object:Gem::Version
|
|
282
273
|
version: '0'
|
|
283
274
|
requirements: []
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
signing_key:
|
|
275
|
+
rubygems_version: 3.1.2
|
|
276
|
+
signing_key:
|
|
287
277
|
specification_version: 4
|
|
288
278
|
summary: A collection of modules to help writing common worker tasks)
|
|
289
279
|
test_files: []
|