k_log 0.0.27 → 0.0.29

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2035ee429ccfbb7cd0307d243e9b8bd303f44444d1b356c28ad079bc8219de8f
4
- data.tar.gz: c7eeff9ee82d1514859052d264cfcb06216ad939f3c215c34dfee6f64ef0d21f
3
+ metadata.gz: 364f495f8acece197a1e085d3e07f29bb60ac455838964932df5fa9d36629879
4
+ data.tar.gz: c181138eee6a0380b555a18ed1d2f798c2bb0f8dd21e7816b3e5e5ef7d7175b7
5
5
  SHA512:
6
- metadata.gz: f12d2c0fae01798339647d3905fefe8e5e63049d074965c04b878e3ba4df7b8571cba637877395f8fa033d2c780d53bfc4aaa2da605af647908fdb7e29bd1e3a
7
- data.tar.gz: 3d780ecca23bac05227ff96629c464f3ecf2ed61f908a6f28145e9b00786fae625e37d751210ccaaf03d613e1683bbfbb15cf009d35e57909ac3110488b34b0f
6
+ metadata.gz: 5c658a445937529a757e33de06f83ce28adc14bef06d4d967b680380dfb2932a7492141579949a6d24408a108e9adb8bebbc63d172f35607e07ab499a1bcf111
7
+ data.tar.gz: 80a20f6658978ab2c0de1e28c9722239dba7c7d926f8e4d9a6ad9d8eb77aafb8bd04945e6fe73a0650f8d3336642f00e9d32da0b4ad4c0e123feef53c6d1f528
@@ -11,6 +11,7 @@ module KLog
11
11
  attr_reader :heading
12
12
  attr_reader :heading_type
13
13
  attr_reader :line_width
14
+ attr_reader :key_width
14
15
  attr_reader :graph
15
16
  attr_reader :formatter
16
17
  attr_reader :convert_data_to
@@ -32,6 +33,7 @@ module KLog
32
33
  # @option opts [String] :heading Log heading using logger.dynamic_heading
33
34
  # @option opts [String] :heading_type :heading, :subheading, :section_heading
34
35
  # @option opts [String] :line_width line width defaults to 80, but can be overridden here
36
+ # @option opts [String] :key_width key width defaults to 30, but can be overridden here
35
37
  # @option opts [String] :formatter is a complex configuration for formatting different data within the structure
36
38
  def initialize(opts)
37
39
  @indent = opts[:indent] || ' '
@@ -48,6 +50,7 @@ module KLog
48
50
  @convert_data_to = opts[:convert_data_to] || :raw # by default leave data as is
49
51
 
50
52
  @line_width = opts[:line_width] || 80
53
+ @key_width = opts[:key_width] || 30
51
54
  @output_as = opts[:output_as] || [:console]
52
55
  @output_as = [@output_as] unless @output_as.is_a?(Array)
53
56
  @output_file = opts[:output_file]
@@ -102,8 +105,13 @@ module KLog
102
105
 
103
106
  # format_config = @formatter[:_root] if format_config.nil? && @recursion_depth.zero?
104
107
 
108
+ def data_enumerator(data)
109
+ return data.attributes if data.respond_to?(:attributes)
110
+ data
111
+ end
112
+
105
113
  def log_data(data)
106
- data.each_pair do |k, v|
114
+ data_enumerator(data).each_pair do |k, v|
107
115
  key = k.is_a?(String) ? k.to_sym : k
108
116
 
109
117
  graph_path.push(key)
@@ -116,21 +124,27 @@ module KLog
116
124
  next
117
125
  end
118
126
 
127
+ binding.pry if graph_node.pry_at?(:before_value)
128
+
119
129
  value = graph_node.transform? ? graph_node.transform(v) : v
120
130
 
121
- case value
122
- when OpenStruct
131
+ binding.pry if graph_node.pry_at?(:after_value)
132
+ case
133
+ when value.is_a?(OpenStruct) || value.respond_to?(:attributes)
134
+
123
135
  # l.kv 'go', 'open struct ->'
136
+ binding.pry if graph_node.pry_at?(:before_structure)
124
137
  log_structure(key, value)
125
138
  # l.kv 'go', 'open struct <-'
126
- when Array
139
+ when value.is_a?(Array)
127
140
  # l.kv 'go', 'array ->'
128
141
  log_array(key, value)
129
142
  # l.kv 'go', 'array <-'
130
143
  else
131
144
  # l.kv 'go', 'value ->'
145
+ binding.pry if graph_node.pry_at?(:before_kv)
132
146
  log_heading(graph_node.heading, graph_node.heading_type) if graph_node.heading
133
- add_line KLog::LogHelper.kv "#{@indent_label}#{key}", value
147
+ add_line KLog::LogHelper.kv("#{@indent_label}#{key}", value, key_width)
134
148
  # l.kv 'go', 'value <-'
135
149
  end
136
150
 
@@ -155,13 +169,15 @@ module KLog
155
169
  end
156
170
 
157
171
  def log_array(key, array)
158
- # return if items.length.zero? && graph_node.skip_empty?
172
+ binding.pry if graph_node.pry_at?(:before_array)
159
173
 
160
174
  items = array.clone
161
175
  items.select! { |item| graph_node.filter(item) } if graph_node.filter?
162
176
  items = items.take(graph_node.take) if graph_node.limited?
163
177
  items.sort!(&graph_node.sort) if graph_node.sort?
164
178
 
179
+ binding.pry if graph_node.pry_at?(:before_array_print)
180
+
165
181
  return if items.length.zero? && graph_node.skip_empty?
166
182
 
167
183
  log_heading(graph_node.heading, graph_node.heading_type) if graph_node.heading
@@ -228,6 +244,7 @@ module KLog
228
244
  def render_output
229
245
  puts content if output_as.include?(:console)
230
246
  File.write(output_file, clean_content) if output_as.include?(:file) && output_file
247
+ # content
231
248
  end
232
249
 
233
250
  # convert_data_to: :open_struct
@@ -390,6 +407,15 @@ module KLog
390
407
  config.skip == true
391
408
  end
392
409
 
410
+ # Useful in complex debug scenarios
411
+ def pry_at
412
+ config.pry_at || []
413
+ end
414
+
415
+ def pry_at?(section)
416
+ pry_at.include?(section)
417
+ end
418
+
393
419
  # Skip empty array node (my be useful for other nodes, but not yet)
394
420
  def skip_empty?
395
421
  config.skip_empty == true
@@ -148,7 +148,7 @@ module KLog
148
148
  # @option opts [String] :heading_type :heading, :subheading, :section_heading
149
149
  # @option opts [Boolean] :skip_array Arrays items can be skipped
150
150
  def structure(data, **opts)
151
- structure = LogStructure.new(**opts)
151
+ structure = LogStructure.new(opts)
152
152
  structure.log(data)
153
153
  end
154
154
 
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.27'
4
+ VERSION = '0.0.29'
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.27
4
+ version: 0.0.29
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-08-29 00:00:00.000000000 Z
11
+ date: 2021-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: k_util