ruby_smart-simple_logger 1.4.0 → 1.5.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
2
  SHA256:
3
- metadata.gz: 499ca8f400db9b2df6a9e3017fece6c7e2b94c32c72feb2d04c3a7013a946c4e
4
- data.tar.gz: f684b602ec79afe45e2cebf5b158eacfab127cd1af7e9aee994a7ec824b0f802
3
+ metadata.gz: 9e26fb30c5d3eea56ec537c9ba5a0cba83cf3c93b9ea251c8260fc95c403d80a
4
+ data.tar.gz: 137db583b36249df9b65e708a4341ba6e8edc3ae128eddb7d4a7c6f15bdf34a4
5
5
  SHA512:
6
- metadata.gz: aa7911b6005d56ffc56585674bd90ff47f07bb0e632b08447c52e4f4222996ca52d783ab44fcae057b034b2920f0b7e0e5cb044be66a7c79be4dcb1ff18abcc6
7
- data.tar.gz: 9f1ae4aed0ca7965cbe57d24223a7283915cf7ab876a467945da7269ea6bb66f292704f7e48400a260542eb5b35dc0898b277c5ad338443e459a529e9f5bebf5
6
+ metadata.gz: de53c20b067bb27ecb7840fe3576e0f0a9aba787b83f599e9644429df74bcff9da4699e8086170bcb306f7b00d4527884cab83628bd971a88fe68a0bb16b9246
7
+ data.tar.gz: f8891751aff164988b69dc37b48d092e5c962ad3755c00d9c3c4010d3519c0fc1db7ed1084ede994d82dead8be2f0a3de47d3fbde9fdded359be81fa45f1b33d
data/docs/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # RubySmart::SimpleLogger - CHANGELOG
2
2
 
3
+ ## [1.5.1] - 2024-09-12
4
+ * **[fix]** `RubySmart::SimpleLogger::KlassLogger` not forwarding kwargs
5
+
6
+ ## [1.5.0] - 2024-09-12
7
+ * **[add]** `SimpleLogger.scene?`-method to check for registered scene options
8
+ * **[ref]** scene options to **keyword**-args _(**WARNING:** This may break existing calls to the scene methods)_
9
+ * **[fix]** `model` scene not calling related scene methods
10
+ * **[fix]** `subject` parameter for default severity-methods not cast as string _(now any object may be provided - which calls `#to_s` method)_
11
+
3
12
  ## [1.4.0] - 2024-07-31
4
13
  * **[add]** 'null'-device / builtin
5
14
  * **[add]** 'debugger'-builtin to send logs to the debugging gem
@@ -370,19 +370,6 @@ module RubySmart
370
370
  res_or_clr.to_sym
371
371
  end
372
372
  end
373
-
374
- # resolves subject & opts from provided args.
375
- # returns provided default subject, if not in args.
376
- # @param [Object] args
377
- # @param [String] subject
378
- # @return [Array]
379
- def _scene_subject_with_opts(args, subject = '')
380
- if args[0].is_a?(Hash)
381
- [subject, args[0]]
382
- else
383
- [args[0] || subject, args[1] || {}]
384
- end
385
- end
386
373
  end
387
374
  end
388
375
  end
@@ -27,6 +27,13 @@ module RubySmart
27
27
  class_variable_set('@@scenes', scenes)
28
28
  end
29
29
 
30
+ # returns true, if provided *key* is a registered scene option
31
+ # @param [Symbol] key
32
+ # @return [Boolean]
33
+ def scene?(key)
34
+ scenes.key?(key)
35
+ end
36
+
30
37
  # registers a new scene by provided key & options
31
38
  # also defines this method by provided block
32
39
  #
@@ -64,11 +71,14 @@ module RubySmart
64
71
 
65
72
  private
66
73
 
67
- # resolves scene options by provided key & merges them with additional options
74
+ # resolves scene options by provided key & merges them with additional *opts*
68
75
  # @param [Symbol] key
69
76
  # @param [Array<Hash>] opts
70
- def _scene_opt(key, *opts)
71
- _opt((scenes[key] || {}), *opts)
77
+ def _scene_opts(key, **opts)
78
+ {
79
+ **(scenes[key] || {}),
80
+ **opts
81
+ }
72
82
  end
73
83
  end
74
84
  end
@@ -9,8 +9,8 @@ module RubySmart
9
9
 
10
10
  module VERSION
11
11
  MAJOR = 1
12
- MINOR = 4
13
- TINY = 0
12
+ MINOR = 5
13
+ TINY = 1
14
14
  PRE = nil
15
15
 
16
16
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
@@ -32,8 +32,8 @@ module RubySmart
32
32
  @klass_logger = nil
33
33
  end
34
34
 
35
- def method_missing(name, *args, &block)
36
- return self.klass_logger.send(name, *args, &block) if self.klass_logger.respond_to? name
35
+ def method_missing(name, *args, **kwargs, &block)
36
+ return self.klass_logger.send(name, *args, **kwargs, &block) if self.klass_logger.respond_to? name
37
37
  super
38
38
  end
39
39
 
@@ -11,9 +11,8 @@ module RubySmart
11
11
  # > ================================================= [Debug] ================================================
12
12
  # > "DEBUGGED DATA" <- analyzed by awesome_print#ai method
13
13
  # > ==========================================================================================================
14
- base.scene :debug, { level: :debug, inspect: true, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data, *args|
15
- subject, opts = _scene_subject_with_opts(args, 'Debug')
16
- self.log data, _scene_opt(:debug, { subject: subject }, opts)
14
+ base.scene :debug, { level: :debug, inspect: true, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data, subject = 'Debug', **opts|
15
+ self.log data, _scene_opts(:debug, subject: subject.to_s, **opts)
17
16
  end
18
17
 
19
18
  # info method (BASE)
@@ -23,9 +22,8 @@ module RubySmart
23
22
  # > ================================================= [Info] =================================================
24
23
  # > DATA
25
24
  # > ==========================================================================================================
26
- base.scene :info, { level: :info, mask: { clr: :cyan }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data, *args|
27
- subject, opts = _scene_subject_with_opts(args, 'Info')
28
- self.log data, _scene_opt(:info, { subject: subject }, opts)
25
+ base.scene :info, { level: :info, mask: { clr: :cyan }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data, subject = 'Info', **opts|
26
+ self.log data, _scene_opts(:info, subject: subject.to_s, **opts)
29
27
  end
30
28
 
31
29
  # warn method (BASE)
@@ -35,9 +33,8 @@ module RubySmart
35
33
  # > ================================================= [Warn] =================================================
36
34
  # > DATA
37
35
  # > ==========================================================================================================
38
- base.scene :warn, { level: :warn, mask: { clr: :yellow }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data, *args|
39
- subject, opts = _scene_subject_with_opts(args, 'Warn')
40
- self.log data, _scene_opt(:warn, { subject: subject }, opts)
36
+ base.scene :warn, { level: :warn, mask: { clr: :yellow }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data, subject = 'Warn', **opts|
37
+ self.log data, _scene_opts(:warn, subject: subject.to_s, **opts)
41
38
  end
42
39
 
43
40
  # error method (BASE)
@@ -47,9 +44,8 @@ module RubySmart
47
44
  # > ================================================ [Error] =================================================
48
45
  # > DATA
49
46
  # > ==========================================================================================================
50
- base.scene :error, { level: :error, mask: { clr: :red }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data, *args|
51
- subject, opts = _scene_subject_with_opts(args, 'Error')
52
- self.log data, _scene_opt(:error, { subject: subject }, opts)
47
+ base.scene :error, { level: :error, mask: { clr: :red }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data, subject = 'Error', **opts|
48
+ self.log data, _scene_opts(:error, subject: subject.to_s, **opts)
53
49
  end
54
50
 
55
51
  # fatal method (BASE)
@@ -59,9 +55,8 @@ module RubySmart
59
55
  # > ================================================ [Fatal] =================================================
60
56
  # > DATA
61
57
  # > ==========================================================================================================
62
- base.scene :fatal, { level: :fatal, mask: { clr: :bg_red }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data, *args|
63
- subject, opts = _scene_subject_with_opts(args, 'Fatal')
64
- self.log data, _scene_opt(:fatal, { subject: subject }, opts)
58
+ base.scene :fatal, { level: :fatal, mask: { clr: :bg_red }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data, subject = 'Fatal', **opts|
59
+ self.log data, _scene_opts(:fatal, subject: subject.to_s, **opts)
65
60
  end
66
61
 
67
62
  # unknown method (BASE)
@@ -71,9 +66,8 @@ module RubySmart
71
66
  # > =============================================== [Unknown] ================================================
72
67
  # > DATA
73
68
  # > ==========================================================================================================
74
- base.scene :unknown, { level: :unknown, mask: { clr: :gray }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data, *args|
75
- subject, opts = _scene_subject_with_opts(args, 'Unknown')
76
- self.log data, _scene_opt(:unknown, { subject: subject }, opts)
69
+ base.scene :unknown, { level: :unknown, mask: { clr: :gray }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data, subject = 'Unknown', **opts|
70
+ self.log data, _scene_opts(:unknown, subject: subject.to_s, **opts)
77
71
  end
78
72
 
79
73
  # success method
@@ -83,9 +77,8 @@ module RubySmart
83
77
  # > ================================================ [Success] ================================================
84
78
  # > DATA
85
79
  # > ===========================================================================================================
86
- base.scene :success, { level: :success, mask: { clr: :green }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data, *args|
87
- subject, opts = _scene_subject_with_opts(args, 'Success')
88
- self.log data, _scene_opt(:success, { subject: subject }, opts)
80
+ base.scene :success, { level: :success, mask: { clr: :green }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data, subject = 'Success', **opts|
81
+ self.log data, _scene_opts(:success, subject: subject.to_s, **opts)
89
82
  end
90
83
 
91
84
  # header method
@@ -95,11 +88,11 @@ module RubySmart
95
88
  # > ===========================================================================================================
96
89
  # > ================================================ <Subject> ================================================
97
90
  # > ===========================================================================================================
98
- base.scene :header, { level: :debug, payload: [:mask, [:mask, ' <%{subject}> '], :mask] } do |subject, opts = {}|
91
+ base.scene :header, { level: :debug, payload: [:mask, [:mask, ' <%{subject}> '], :mask] } do |subject, **opts|
99
92
  # autostart a timer method, if required
100
93
  self.timer(:start, :default) if opts[:timer]
101
94
 
102
- self.log nil, _scene_opt(:header, { subject: subject }, opts)
95
+ self.log nil, _scene_opts(:header, subject: subject.to_s, **opts)
103
96
  end
104
97
 
105
98
  # footer method
@@ -109,8 +102,8 @@ module RubySmart
109
102
  # > ===========================================================================================================
110
103
  # > ================================================ >Subject< ================================================
111
104
  # > ===========================================================================================================
112
- base.scene :footer, { level: :debug, payload: [:mask, [:mask, ' >%{subject}< '], :mask] } do |subject, opts = {}|
113
- self.log nil, _scene_opt(:footer, { subject: subject }, opts)
105
+ base.scene :footer, { level: :debug, payload: [:mask, [:mask, ' >%{subject}< '], :mask] } do |subject, **opts|
106
+ self.log nil, _scene_opts(:footer, subject: subject.to_s, **opts)
114
107
 
115
108
  # clears & prints timer
116
109
  self.desc("duration: #{self.timer(:clear, :default, :humanized => true)}") if opts[:timer]
@@ -123,8 +116,8 @@ module RubySmart
123
116
  # > --------------------------------------------------------------------------------
124
117
  # > #----------------------------------- Subject ----------------------------------#
125
118
  # > --------------------------------------------------------------------------------
126
- base.scene :topic, { level: :debug, mask: { char: '-', length: 95, clr: :blueish }, payload: [:mask, [:mask, '%{title}'], :mask] } do |subject, opts = {}|
127
- opts = _scene_opt(:topic, opts)
119
+ base.scene :topic, { level: :debug, mask: { char: '-', length: 95, clr: :blueish }, payload: [:mask, [:mask, '%{title}'], :mask] } do |subject, **opts|
120
+ opts = _scene_opts(:topic, **opts)
128
121
  txt = " #{subject} ".center(opts[:mask][:length] - 2, opts[:mask][:char])
129
122
  opts[:title] = "##{txt}#"
130
123
 
@@ -137,8 +130,8 @@ module RubySmart
137
130
  #
138
131
  # > # Subject
139
132
  # > ----------------------------------------------------------------------
140
- base.scene :theme, { level: :debug, clr: :purple, mask: { char: '-', length: 85, clr: :purple }, payload: [[:txt, '# %{subject}'], :mask] } do |subject, opts = {}|
141
- self.log nil, _scene_opt(:theme, { subject: subject }, opts)
133
+ base.scene :theme, { level: :debug, clr: :purple, mask: { char: '-', length: 85, clr: :purple }, payload: [[:txt, '# %{subject}'], :mask] } do |subject, **opts|
134
+ self.log nil, _scene_opts(:theme, subject: subject.to_s, **opts)
142
135
  end
143
136
 
144
137
  # theme_result method
@@ -148,9 +141,9 @@ module RubySmart
148
141
  # > ----------------------------------------------------------------------
149
142
  # > -> Result
150
143
  # >
151
- base.scene :theme_result, { level: :debug, mask: { char: '-', length: 85, clr: :purple }, payload: [:mask, [:txt, '-> %{result}'], ''] } do |result, status = nil, opts = {}|
144
+ base.scene :theme_result, { level: :debug, mask: { char: '-', length: 85, clr: :purple }, payload: [:mask, [:txt, '-> %{result}'], ''] } do |result, status = nil, **opts|
152
145
  res_or_clr = status.nil? ? result : status
153
- self.log nil, _scene_opt(:theme_result, { result: result, clr: _res_clr(res_or_clr) }, opts)
146
+ self.log nil, _scene_opts(:theme_result, result: result, clr: _res_clr(res_or_clr), **opts)
154
147
  end
155
148
 
156
149
  # theme_line method
@@ -158,8 +151,8 @@ module RubySmart
158
151
  # prints: colored line with no text
159
152
  #
160
153
  # > ----------------------------------------------------------------------
161
- base.scene :theme_line, { level: :debug, mask: { char: '-', length: 85, clr: :purple }, payload: [:mask] } do |opts = {}|
162
- self.log nil, _scene_opt(:theme_line, opts)
154
+ base.scene :theme_line, { level: :debug, mask: { char: '-', length: 85, clr: :purple }, payload: [:mask] } do |**opts|
155
+ self.log nil, _scene_opts(:theme_line, **opts)
163
156
  end
164
157
 
165
158
  # desc method
@@ -168,8 +161,8 @@ module RubySmart
168
161
  #
169
162
  # > "description"
170
163
  # >
171
- base.scene :desc, { level: :debug, clr: :purple, payload: [[:txt, '%{description}']] } do |description, opts = {}|
172
- self.log nil, _scene_opt(:desc, { description: description.to_s }, opts)
164
+ base.scene :desc, { level: :debug, clr: :purple, payload: [[:txt, '%{description}']] } do |description, **opts|
165
+ self.log nil, _scene_opts(:desc, description: description.to_s, **opts)
173
166
  end
174
167
 
175
168
  # job method
@@ -179,8 +172,8 @@ module RubySmart
179
172
  #
180
173
  # > - Job name =>
181
174
  # ________________________________________________________________ <- 64 chars
182
- base.scene :job, { level: :debug, clr: :cyan, nl: false, length: 64, payload: [[:concat, ['- ', [:txt, '%{name}'], ' => ']]] } do |name, opts = {}, &block|
183
- self.log nil, _scene_opt(:job, { name: name }, opts)
175
+ base.scene :job, { level: :debug, clr: :cyan, nl: false, length: 64, payload: [[:concat, ['- ', [:txt, '%{name}'], ' => ']]] } do |name, **opts, &block|
176
+ self.log nil, _scene_opts(:job, name: name, **opts)
184
177
  self.result(*block.call) if block_given?
185
178
  end
186
179
 
@@ -191,8 +184,8 @@ module RubySmart
191
184
  #
192
185
  # > * Subjob name =>
193
186
  # ______________________________________________________________ <- 62 chars
194
- base.scene :sub_job, { level: :debug, clr: :cyan, nl: false, length: 62, payload: [[:concat, [' * ', [:txt, '%{name}'], ' => ']]] } do |name, opts = {}, &block|
195
- self.log nil, _scene_opt(:sub_job, { name: name }, opts)
187
+ base.scene :sub_job, { level: :debug, clr: :cyan, nl: false, length: 62, payload: [[:concat, [' * ', [:txt, '%{name}'], ' => ']]] } do |name, **opts, &block|
188
+ self.log nil, _scene_opts(:sub_job, name: name, **opts)
196
189
  self.result(*block.call) if block_given?
197
190
  end
198
191
 
@@ -201,9 +194,9 @@ module RubySmart
201
194
  # prints: colored result
202
195
  #
203
196
  # > Result
204
- base.scene :result, { level: :debug, payload: [[:txt, '%{result}']] } do |result, status = nil, opts = {}|
197
+ base.scene :result, { level: :debug, payload: [[:txt, '%{result}']] } do |result, status = nil, **opts|
205
198
  res_or_clr = status.nil? ? result : status
206
- self.log nil, _scene_opt(:result, { result: result, clr: _res_clr(res_or_clr) }, opts)
199
+ self.log nil, _scene_opts(:result, result: result, clr: _res_clr(res_or_clr), **opts)
207
200
  end
208
201
 
209
202
  # job_result method
@@ -211,9 +204,9 @@ module RubySmart
211
204
  # prints: job with combined colored result
212
205
  #
213
206
  # > - Job name => Result
214
- base.scene :job_result, { level: :debug } do |name, result, status = nil, opts = {}|
215
- self.job(name, opts)
216
- self.result(result, status, opts)
207
+ base.scene :job_result, { level: :debug } do |name, result, status = nil, **opts|
208
+ self.job(name, **opts)
209
+ self.result(result, status, **opts)
217
210
  end
218
211
 
219
212
  # sub_job_result method
@@ -221,9 +214,9 @@ module RubySmart
221
214
  # prints: sub_job with combined colored result
222
215
  #
223
216
  # > * Subjob name => Result
224
- base.scene :sub_job_result, { level: :debug } do |name, result, status = nil, opts = {}|
225
- self.sub_job(name, opts)
226
- self.result(result, status, opts)
217
+ base.scene :sub_job_result, { level: :debug } do |name, result, status = nil, **opts|
218
+ self.sub_job(name, **opts)
219
+ self.result(result, status, **opts)
227
220
  end
228
221
 
229
222
  # line method
@@ -231,8 +224,8 @@ module RubySmart
231
224
  # prints: just a line with data
232
225
  #
233
226
  # > DATA
234
- base.scene :line, { level: :debug } do |data, opts = {}|
235
- self.log data, _scene_opt(:line, opts)
227
+ base.scene :line, { level: :debug } do |data, **opts|
228
+ self.log data, _scene_opts(:line, **opts)
236
229
  end
237
230
 
238
231
  # print method
@@ -240,8 +233,8 @@ module RubySmart
240
233
  # prints: prints data without a newline
241
234
  #
242
235
  # > DATA
243
- base.scene :print, { level: :debug, nl: false } do |data, opts = {}|
244
- self.log data, _scene_opt(:print, opts)
236
+ base.scene :print, { level: :debug, nl: false } do |data, **opts|
237
+ self.log data, _scene_opts(:print, **opts)
245
238
  end
246
239
 
247
240
  # nl method
@@ -250,8 +243,8 @@ module RubySmart
250
243
  #
251
244
  # >
252
245
  # >
253
- base.scene :nl, { level: :debug } do |opts = {}|
254
- self.log '', _scene_opt(:nl, opts)
246
+ base.scene :nl, { level: :debug } do |**opts|
247
+ self.log '', _scene_opts(:nl, **opts)
255
248
  end
256
249
 
257
250
  # spec method
@@ -263,7 +256,7 @@ module RubySmart
263
256
  # "other" => ? (yellow)
264
257
  #
265
258
  # > .FFF...??...F....F...F..???....F...??
266
- base.scene :spec, { level: :debug, nl: false, payload: [[:txt, '%{result}']] } do |status, opts = {}|
259
+ base.scene :spec, { level: :debug, nl: false, payload: [[:txt, '%{result}']] } do |status, **opts|
267
260
  result = if status.is_a?(TrueClass)
268
261
  '.'
269
262
  elsif status.is_a?(FalseClass)
@@ -272,7 +265,7 @@ module RubySmart
272
265
  status = :yellow
273
266
  '?'
274
267
  end
275
- self.log nil, _scene_opt(:spec, { result: result, clr: _res_clr(status) }, opts)
268
+ self.log nil, _scene_opts(:spec, result: result, clr: _res_clr(status), **opts)
276
269
  end
277
270
 
278
271
  # progress method
@@ -283,7 +276,7 @@ module RubySmart
283
276
  # > - Progress of Step 1 [ 40%] ===================>------------------------------
284
277
  # ________________________________________________ <- 48 chars
285
278
  # 50 chars -> __________________________________________________
286
- base.scene :progress, { level: :debug, payload: [[:txt, '- %{name} [%{perc}%] %{progress}']] } do |name, perc, opts = {}|
279
+ base.scene :progress, { level: :debug, payload: [[:txt, '- %{name} [%{perc}%] %{progress}']] } do |name, perc, **opts|
287
280
  pmask_length = 50
288
281
 
289
282
  # convert and fix progress
@@ -298,7 +291,7 @@ module RubySmart
298
291
 
299
292
  progress_string = _clr(('=' * pmask_left_length) + '>', :green) + _clr('-' * pmask_right_length, :red)
300
293
  perc_string = perc.to_s.rjust(3, ' ')
301
- self.log nil, _scene_opt(:progress, { name: _clr(_lgth(name, 48), :cyan), perc: perc_string, progress: progress_string }, opts)
294
+ self.log nil, _scene_opts(:progress, name: _clr(_lgth(name, 48), :cyan), perc: perc_string, progress: progress_string, **opts)
302
295
  end
303
296
 
304
297
  # processed method
@@ -309,7 +302,7 @@ module RubySmart
309
302
  # ╟ doing some cool log
310
303
  # ╟ doing some extra log
311
304
  # ╚ END ❯ job [SUCCESS] (duration: 4.34223)
312
- base.scene :processed, { level: :debug } do |name, opts = {}, &block|
305
+ base.scene :processed, { level: :debug } do |name, **opts, &block|
313
306
  # increase level
314
307
  lvl = processed_lvl(:up)
315
308
 
@@ -326,7 +319,7 @@ module RubySmart
326
319
  self.timer(:start, timer_key)
327
320
 
328
321
  # send START name as +data+ - the full log line is created through the +_pcd+ method.
329
- self.log(name, _scene_opt(:processed, opts, { pcd: :start }))
322
+ self.log(name, _scene_opts(:processed, **opts, pcd: :start))
330
323
 
331
324
  # run the provided block and resolve result
332
325
  result_str = case block.call
@@ -345,7 +338,7 @@ module RubySmart
345
338
  result_str ||= ''
346
339
 
347
340
  # send END name with result & possible time as +data+ - the full log line is created through the +_pcd+ method.
348
- self.log("#{name} #{result_str}#{(timer_key ? "(#{self.timer(:clear, timer_key, humanized: true)})" : '')}", _scene_opt(:processed, opts, { pcd: :end }))
341
+ self.log("#{name} #{result_str}#{(timer_key ? "(#{self.timer(:clear, timer_key, humanized: true)})" : '')}", _scene_opts(:processed, **opts, pcd: :end ))
349
342
 
350
343
  # reduce level
351
344
  processed_lvl(:down)
@@ -357,26 +350,27 @@ module RubySmart
357
350
  # model method
358
351
  # log level @ error/success/info
359
352
  # prints: ActiveRecord::Base related data, depending on the models "save" state (also shows possible errors)
360
- base.scene :model do |model, opts = {}|
353
+ base.scene :model do |model, status = nil, **opts|
361
354
  # build model-logging string
362
355
  mdl_string = "#{model.id.present? ? "##{model.id} - " : ''}#{model.to_s[0..49]}"
363
356
 
364
357
  # resolve model's status
365
- status = ((model.persisted? && model.errors.empty?) ? (model.previous_changes.blank? ? :skipped : :success) : :error)
358
+ status = ((model.persisted? && model.errors.empty?) ? (model.previous_changes.blank? ? :skipped : :success) : :error) if status.nil?
366
359
 
367
360
  # switch between status
368
361
  case status
369
362
  when :success
370
363
  # show verbose logging for updated records
371
364
  if opts[:verbose] != false && !model.previously_new_record?
372
- log(:success, "#{mdl_string} (#{model.previous_changes.inspect})", tag: "#{model.class.name.upcase}|UPDATED")
365
+ self.success("#{mdl_string} (#{model.previous_changes.inspect})", tag: "#{model.class.name.upcase}|UPDATED", **opts)
373
366
  else
374
- log(:success, mdl_string, tag: "#{model.class.name.upcase}|#{(model.previously_new_record? ? 'CREATED' : 'UPDATED')}")
367
+ self.success(mdl_string, tag: "#{model.class.name.upcase}|#{(model.previously_new_record? ? 'CREATED' : 'UPDATED')}", **opts)
375
368
  end
376
369
  when :error
377
- log(:error, "#{mdl_string} (#{model.errors.full_messages.join(', ').presence || '-'})", tag: "#{model.class.name.upcase}|ERROR")
370
+ msg_string = model.errors.full_messages.join(', ')
371
+ self.error("#{mdl_string} (#{msg_string.present? ? msg_string : '-'})", tag: "#{model.class.name.upcase}|ERROR", **opts)
378
372
  else
379
- log(:info, mdl_string, tag: "#{model.class.name.upcase}|#{status}")
373
+ self.info(mdl_string, tag: "#{model.class.name.upcase}|#{status}", **opts)
380
374
  end
381
375
  end
382
376
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_smart-simple_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Gonsior
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-31 00:00:00.000000000 Z
11
+ date: 2024-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby_smart-support