worker_tools 0.1.2 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f8781038bd01108da06e6c7449cb29faaa45fdd8
4
- data.tar.gz: eed78607ccda5d5b0ed7ad5030a42b8dc286fcea
2
+ SHA256:
3
+ metadata.gz: a1660c965e25b8331d1aa6a7643f5bee9f0441c02a6593ce71028c7e89ea4c14
4
+ data.tar.gz: 06c98881c9cf9a1f8c1312a8fbbff6bdc3c4471203cdb0678f89cd8570e4c8e4
5
5
  SHA512:
6
- metadata.gz: cc5633debc66182adff1af028ae0034937be1d369abbaabdbc731da5e792480db6074b602e951efaf4ec1889d0586fd175b44df4945eff8819d637cdfec171c8
7
- data.tar.gz: d6dcb02514729dcf459df1eaee5f40df1a792731336aea56a8b92541418163227b17144174285075e5365f98546c0a2607534c5b62845bee1e0982c94dd9bb39
6
+ metadata.gz: d3b7e56590008364884c685285be80264c435ff4b6129649e9c8f1b26ae01d4655c352390896cf2e5ca8726ba537933812cf15eedc6cae73be8de60d8e8a1178
7
+ data.tar.gz: fcb3b2479c852071296443df0cdca53aba6ace592231a14011436013b52591650c2b558d0955c067ef37a4ae16bce4f873f62fbe9681841ba047b686ede87544
@@ -2,4 +2,5 @@ sudo: false
2
2
  language: ruby
3
3
  rvm:
4
4
  - 2.3.1
5
- before_install: gem install bundler -v 1.14.6
5
+ - 2.7.0
6
+ before_install: gem install bundler -v 2.1.4
data/README.md CHANGED
@@ -124,10 +124,6 @@ If you only want the logger functions, without worrying about persisting a model
124
124
  end
125
125
  ```
126
126
 
127
- ## Module RocketchatErrorNotifier
128
-
129
- [rocketchat_error_notifier](/lib/worker_tools/rocketchat_error_notifier.rb)
130
-
131
127
  ## Module SlackErrorNotifier
132
128
 
133
129
  [slack_error_notifier](/lib/worker_tools/slack_error_notifier.rb)
@@ -212,4 +208,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/i22-di
212
208
  ## License
213
209
 
214
210
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
215
-
@@ -42,6 +42,7 @@ module WorkerTools
42
42
  self.class.read_wrappers.map do |wrapper|
43
43
  symbolized_method = "with_wrapper_#{wrapper}".to_sym
44
44
  raise "Missing wrapper #{wrapper}" unless respond_to?(symbolized_method)
45
+
45
46
  symbolized_method
46
47
  end
47
48
  end
@@ -60,7 +61,7 @@ module WorkerTools
60
61
  end
61
62
 
62
63
  def finalize
63
- model.update_attributes!(
64
+ model.update!(
64
65
  state: 'complete',
65
66
  information: information
66
67
  )
@@ -76,6 +77,7 @@ module WorkerTools
76
77
 
77
78
  def with_wrappers(wrapper_symbols, &block)
78
79
  return yield if wrapper_symbols.blank?
80
+
79
81
  current_wrapper_symbol = wrapper_symbols.shift
80
82
  send(current_wrapper_symbol) { with_wrappers(wrapper_symbols, &block) }
81
83
  end
@@ -87,6 +89,7 @@ module WorkerTools
87
89
  return @model_id if @model_id.is_a?(model_class)
88
90
  return model_class.find(@model_id) if @model_id
89
91
  raise 'Model not available' unless create_model_if_not_available
92
+
90
93
  t = model_class.new
91
94
  t.kind = model_kind if t.respond_to?(:kind=)
92
95
  t.save!(validate: false)
@@ -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,6 +62,7 @@ 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
65
+
64
66
  raise "The number of columns (#{actual_columns_length}) is not the expected (#{expected_columns_length})"
65
67
  end
66
68
 
@@ -105,6 +107,7 @@ module WorkerTools
105
107
  # => { tenant: 1, area: 0}
106
108
  def csv_input_mapping_order(header_names)
107
109
  return csv_input_columns.map.with_index { |n, i| [n, i] }.to_h if csv_input_columns.is_a?(Array)
110
+
108
111
  csv_input_mapping_order_for_hash(header_names)
109
112
  end
110
113
 
@@ -115,6 +118,7 @@ module WorkerTools
115
118
  h[k] = filtered_column_names.index { |n| case n when matchable then true end }
116
119
  end
117
120
  return mapping unless csv_input_include_other_columns
121
+
118
122
  csv_input_mapping_order_with_other_columns(mapping, filtered_column_names)
119
123
  end
120
124
 
@@ -131,7 +135,7 @@ module WorkerTools
131
135
  end
132
136
 
133
137
  def csv_rows_enum
134
- @csv_rows_enum ||= CSV.foreach(csv_input_file_path, csv_input_csv_options)
138
+ @csv_rows_enum ||= CSV.foreach(csv_input_file_path, **csv_input_csv_options)
135
139
  end
136
140
 
137
141
  def csv_input_headers_present
@@ -168,12 +172,14 @@ module WorkerTools
168
172
 
169
173
  @rows_enum.with_index.each do |values, index|
170
174
  next if index.zero? && @headers_present
175
+
171
176
  yield values_to_row(values)
172
177
  end
173
178
  end
174
179
 
175
180
  def values_to_row(values)
176
181
  return values_to_row_according_to_mapping(values) if @mapping_order
182
+
177
183
  values_to_row_according_to_position(values)
178
184
  end
179
185
 
@@ -45,11 +45,13 @@ module WorkerTools
45
45
 
46
46
  def format_log_message(message)
47
47
  return error_to_text(message, log_error_trace_lines) if message.is_a?(Exception)
48
+
48
49
  message
49
50
  end
50
51
 
51
52
  def format_info_message(message)
52
53
  return error_to_text(message, info_error_trace_lines) if message.is_a?(Exception)
54
+
53
55
  message
54
56
  end
55
57
 
@@ -83,7 +83,7 @@ module WorkerTools
83
83
 
84
84
  def slack_error_notifier_attachments_fields
85
85
  [
86
- { title: 'Application', value: Rails.application.class.parent_name, short: true },
86
+ { title: 'Application', value: Rails.application.class.module_parent_name, short: true },
87
87
  { title: 'Environment', value: Rails.env, short: true }
88
88
  ]
89
89
  end
@@ -1,3 +1,3 @@
1
1
  module WorkerTools
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '0.2.1'.freeze
3
3
  end
@@ -59,6 +59,7 @@ module WorkerTools
59
59
  def xlsx_input_columns_check(xlsx_rows_enum)
60
60
  # override and return true if you do not want this check to be performed
61
61
  return xlsx_input_columns_array_check(xlsx_rows_enum) if xlsx_input_columns.is_a?(Array)
62
+
62
63
  xlsx_input_columns_hash_check(xlsx_rows_enum)
63
64
  end
64
65
 
@@ -66,6 +67,7 @@ module WorkerTools
66
67
  expected_columns_length = xlsx_input_columns.length
67
68
  actual_columns_length = xlsx_rows_enum.first.length
68
69
  return if expected_columns_length == actual_columns_length
70
+
69
71
  raise "The number of columns (#{actual_columns_length}) is not the expected (#{expected_columns_length})"
70
72
  end
71
73
 
@@ -97,6 +99,7 @@ module WorkerTools
97
99
  # => { tenant: 1, area: 0}
98
100
  def xlsx_input_mapping_order(header_names)
99
101
  return xlsx_input_columns.map.with_index { |n, i| [n, i] }.to_h if xlsx_input_columns.is_a?(Array)
102
+
100
103
  xlsx_input_mapping_order_for_hash(header_names)
101
104
  end
102
105
 
@@ -107,6 +110,7 @@ module WorkerTools
107
110
  h[k] = filtered_column_names.index { |n| case n when matchable then true end }
108
111
  end
109
112
  return mapping unless xlsx_input_include_other_columns
113
+
110
114
  xlsx_input_mapping_order_with_other_columns(mapping, filtered_column_names)
111
115
  end
112
116
 
@@ -155,6 +159,7 @@ module WorkerTools
155
159
 
156
160
  @rows_enum.with_index.each do |values, index|
157
161
  next if index.zero? # headers
162
+
158
163
  yield values_to_row(values)
159
164
  end
160
165
  end
@@ -61,6 +61,7 @@ module WorkerTools
61
61
 
62
62
  def xlsx_insert_headers(spreadsheet, headers)
63
63
  return unless headers
64
+
64
65
  iterator =
65
66
  if headers.is_a? Hash
66
67
  headers.values
@@ -83,6 +84,7 @@ module WorkerTools
83
84
  def xlsx_iterators(iterable, compare_hash = nil)
84
85
  if iterable.is_a? Hash
85
86
  raise 'parameter compare_hash should be a hash, too.' if compare_hash.nil? || !compare_hash.is_a?(Hash)
87
+
86
88
  iterable.values_at(*compare_hash.keys)
87
89
  else
88
90
  iterable
@@ -94,6 +96,7 @@ module WorkerTools
94
96
 
95
97
  xlsx_iterators(styles, headers).each_with_index do |format, index|
96
98
  next unless format
99
+
97
100
  spreadsheet.change_column_width(index, format[:width])
98
101
  spreadsheet.change_text_wrap(index, format[:text_wrap])
99
102
  end
@@ -1,4 +1,4 @@
1
- lib = File.expand_path('../lib', __FILE__)
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.52.1'
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.1.2
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - fsainz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-03-18 00:00:00.000000000 Z
11
+ date: 2020-10-01 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.52.1
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.52.1
194
+ version: 0.71.0
209
195
  - !ruby/object:Gem::Dependency
210
196
  name: simplecov
211
197
  requirement: !ruby/object:Gem::Requirement
@@ -255,7 +241,6 @@ files:
255
241
  - lib/worker_tools/csv_input.rb
256
242
  - lib/worker_tools/csv_output.rb
257
243
  - lib/worker_tools/recorder.rb
258
- - lib/worker_tools/rocketchat_error_notifier.rb
259
244
  - lib/worker_tools/slack_error_notifier.rb
260
245
  - lib/worker_tools/version.rb
261
246
  - lib/worker_tools/xlsx_input.rb
@@ -281,8 +266,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
281
266
  - !ruby/object:Gem::Version
282
267
  version: '0'
283
268
  requirements: []
284
- rubyforge_project:
285
- rubygems_version: 2.5.1
269
+ rubygems_version: 3.1.2
286
270
  signing_key:
287
271
  specification_version: 4
288
272
  summary: A collection of modules to help writing common worker tasks)
@@ -1,68 +0,0 @@
1
- module WorkerTools
2
- module RocketchatErrorNotifier
3
- def with_wrapper_rocketchat_error_notifier(&block)
4
- block.yield
5
- rescue StandardError => e
6
- rocketchat_error_notify(e) if rocketchat_error_notifier_enabled
7
- raise
8
- end
9
-
10
- def rocketchat_error_notifier_enabled
11
- Rails.env.production?
12
- end
13
-
14
- def rocketchat_error_notifier_emoji
15
- ':red_circle:'
16
- end
17
-
18
- def rocketchat_error_notifier_receivers
19
- # Ex: '@all'
20
- end
21
-
22
- def rocketchat_error_notifier_event
23
- 'Worker Error Notifier'
24
- end
25
-
26
- def rocketchat_error_notifier_title
27
- # Example with a link:
28
- #
29
- # For urls a default_url_options[:host] might be necessary.
30
- # In this example I just copy it from existing action_mailer defaults.
31
- #
32
- # import = rocketchat_error_notifier_model
33
- # host = Rails.application.config.action_mailer.default_url_options[:host]
34
- # url = Rails.application.routes.url_helpers.import_url(import, host: host, protocol: :https)
35
- # kind = I18n.t(import.kind, scope: 'import.kinds')
36
- # text = "##{import.id} *#{kind}*"
37
- # "[#{text}](#{url})"
38
- klass = model.class.model_name.human
39
- kind = I18n.t("activerecord.attributes.#{model.class.name.underscore}.kinds.#{model.kind}")
40
- "#{klass} #{kind} ##{model.id}"
41
- end
42
-
43
- def rocketchat_error_notifier_error_details(error)
44
- details = "#{error.class}: #{error.message}\n"
45
- details << error.backtrace[0..10].join("\n")
46
- end
47
-
48
- def rocketchat_error_notifier_message
49
- message = []
50
- message << rocketchat_error_notifier_receivers
51
- message << rocketchat_error_notifier_title
52
- message.compact.join(' - ')
53
- end
54
-
55
- def rocketchat_error_notifier_attachment(error)
56
- { collapsed: true, title: 'Error', text: rocketchat_error_notifier_error_details(error) }
57
- end
58
-
59
- def rocketchat_error_notify(error)
60
- RocketChatNotifier.notify(
61
- rocketchat_error_notifier_message,
62
- emoji: rocketchat_error_notifier_emoji,
63
- event: "#{rocketchat_error_notifier_event} (#{Rails.env})",
64
- attachment: rocketchat_error_notifier_attachment(error)
65
- )
66
- end
67
- end
68
- end