k_log 0.0.29 → 0.0.30

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: 364f495f8acece197a1e085d3e07f29bb60ac455838964932df5fa9d36629879
4
- data.tar.gz: c181138eee6a0380b555a18ed1d2f798c2bb0f8dd21e7816b3e5e5ef7d7175b7
3
+ metadata.gz: 328dd6fd19c8872158c3de15cbcb0bc2cf222ca2124b8d03ce81a81040cd1411
4
+ data.tar.gz: f44defe61b5895b2505725c2cbad5c27c45c93e155e25460a85d1a083f1cb775
5
5
  SHA512:
6
- metadata.gz: 5c658a445937529a757e33de06f83ce28adc14bef06d4d967b680380dfb2932a7492141579949a6d24408a108e9adb8bebbc63d172f35607e07ab499a1bcf111
7
- data.tar.gz: 80a20f6658978ab2c0de1e28c9722239dba7c7d926f8e4d9a6ad9d8eb77aafb8bd04945e6fe73a0650f8d3336642f00e9d32da0b4ad4c0e123feef53c6d1f528
6
+ metadata.gz: 0753d0d203b0673a2526368fa92a6cd6fc0c7ba42f6d425dbaba54b489b9db8e8865bbba2a1b6c22804c6e47b74e1f885b1cb11c85cb9c922fb99d34c30ea21d
7
+ data.tar.gz: 436f881ffb78b39ded0f7d2649712286c74c39e104991b8fd28cfc7b7dc7417c91f64030d82ab9a54bb3d17ce6d6ae7c64bfe2ccc955b2ccff6f71b43d5dd72e
@@ -12,6 +12,7 @@ module KLog
12
12
  attr_reader :heading_type
13
13
  attr_reader :line_width
14
14
  attr_reader :key_width
15
+ attr_reader :show_array_count
15
16
  attr_reader :graph
16
17
  attr_reader :formatter
17
18
  attr_reader :convert_data_to
@@ -51,6 +52,7 @@ module KLog
51
52
 
52
53
  @line_width = opts[:line_width] || 80
53
54
  @key_width = opts[:key_width] || 30
55
+ @show_array_count = opts[:show_array_count] || false
54
56
  @output_as = opts[:output_as] || [:console]
55
57
  @output_as = [@output_as] unless @output_as.is_a?(Array)
56
58
  @output_file = opts[:output_file]
@@ -107,6 +109,7 @@ module KLog
107
109
 
108
110
  def data_enumerator(data)
109
111
  return data.attributes if data.respond_to?(:attributes)
112
+
110
113
  data
111
114
  end
112
115
 
@@ -115,7 +118,7 @@ module KLog
115
118
  key = k.is_a?(String) ? k.to_sym : k
116
119
 
117
120
  graph_path.push(key)
118
- @graph_node = GraphNode.for(graph, graph_path)
121
+ @graph_node = GraphNode.for(self, graph, graph_path)
119
122
  # l.kv 'key', "#{key.to_s.ljust(15)}#{graph_node.skip?.to_s.ljust(6)}#{@recursion_depth}"
120
123
 
121
124
  if graph_node.skip?
@@ -124,25 +127,24 @@ module KLog
124
127
  next
125
128
  end
126
129
 
127
- binding.pry if graph_node.pry_at?(:before_value)
130
+ 'puts xmen' if graph_node.pry_at?(:before_value)
128
131
 
129
132
  value = graph_node.transform? ? graph_node.transform(v) : v
130
133
 
131
- binding.pry if graph_node.pry_at?(:after_value)
132
- case
133
- when value.is_a?(OpenStruct) || value.respond_to?(:attributes)
134
+ 'puts xmen' if graph_node.pry_at?(:after_value)
135
+ if value.is_a?(OpenStruct) || value.respond_to?(:attributes)
134
136
 
135
137
  # l.kv 'go', 'open struct ->'
136
- binding.pry if graph_node.pry_at?(:before_structure)
138
+ 'puts xmen' if graph_node.pry_at?(:before_structure)
137
139
  log_structure(key, value)
138
140
  # l.kv 'go', 'open struct <-'
139
- when value.is_a?(Array)
141
+ elsif value.is_a?(Array)
140
142
  # l.kv 'go', 'array ->'
141
143
  log_array(key, value)
142
144
  # l.kv 'go', 'array <-'
143
145
  else
144
146
  # l.kv 'go', 'value ->'
145
- binding.pry if graph_node.pry_at?(:before_kv)
147
+ 'puts xmen' if graph_node.pry_at?(:before_kv)
146
148
  log_heading(graph_node.heading, graph_node.heading_type) if graph_node.heading
147
149
  add_line KLog::LogHelper.kv("#{@indent_label}#{key}", value, key_width)
148
150
  # l.kv 'go', 'value <-'
@@ -169,14 +171,14 @@ module KLog
169
171
  end
170
172
 
171
173
  def log_array(key, array)
172
- binding.pry if graph_node.pry_at?(:before_array)
174
+ 'puts xmen' if graph_node.pry_at?(:before_array)
173
175
 
174
176
  items = array.clone
175
177
  items.select! { |item| graph_node.filter(item) } if graph_node.filter?
176
178
  items = items.take(graph_node.take) if graph_node.limited?
177
179
  items.sort!(&graph_node.sort) if graph_node.sort?
178
180
 
179
- binding.pry if graph_node.pry_at?(:before_array_print)
181
+ 'puts xmen' if graph_node.pry_at?(:before_array_print)
180
182
 
181
183
  return if items.length.zero? && graph_node.skip_empty?
182
184
 
@@ -186,9 +188,12 @@ module KLog
186
188
  add_line KLog::LogHelper.kv "#{@indent_label}#{key}", items.map(&:to_s).join(', ')
187
189
  else
188
190
  table_print items, tp_columns(items)
191
+
192
+ # NEED SUPPORT FOR A configured ARRAY COUNT with width and label
193
+ add_line KLog::LogHelper.kv key.to_s, items.count if show_array_count
189
194
  end
190
- rescue StandardError
191
- #
195
+ rescue StandardError => e
196
+ KLog.logger.exception(e)
192
197
  end
193
198
 
194
199
  def table_print(items, columns)
@@ -321,6 +326,7 @@ module KLog
321
326
  end
322
327
 
323
328
  class GraphNode
329
+ attr_reader :log_structure
324
330
  attr_accessor :config
325
331
 
326
332
  class << self
@@ -328,7 +334,7 @@ module KLog
328
334
  @null ||= OpenStruct.new
329
335
  end
330
336
 
331
- def for(graph, graph_path)
337
+ def for(log_structure, graph, graph_path)
332
338
  # node_config = graph_path.inject(graph, :send) # (uses deep nesting, but fails when nil is returned) https://stackoverflow.com/questions/15862455/ruby-nested-send
333
339
  # node.nil? ? null : node.send(name) || null
334
340
  node_config = graph_path.reduce(graph) do |node, name|
@@ -339,11 +345,12 @@ module KLog
339
345
  result
340
346
  end
341
347
 
342
- new(node_config)
348
+ new(log_structure, node_config)
343
349
  end
344
350
  end
345
351
 
346
- def initialize(config)
352
+ def initialize(log_structure, config)
353
+ @log_structure = log_structure
347
354
  @config = config || OpenStruct.new
348
355
  end
349
356
 
@@ -415,11 +422,15 @@ module KLog
415
422
  def pry_at?(section)
416
423
  pry_at.include?(section)
417
424
  end
418
-
425
+
419
426
  # Skip empty array node (my be useful for other nodes, but not yet)
420
427
  def skip_empty?
421
428
  config.skip_empty == true
422
429
  end
430
+
431
+ def show_array_count
432
+ log_structure.show_array_count
433
+ end
423
434
  end
424
435
  end
425
436
  end
data/lib/k_log/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KLog
4
- VERSION = '0.0.29'
4
+ VERSION = '0.0.30'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: k_log
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.29
4
+ version: 0.0.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cruwys
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-03 00:00:00.000000000 Z
11
+ date: 2021-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: k_util