Class: KLog::LogStructure::GraphNode

Inherits:
Object
  • Object
show all
Defined in:
lib/k_log/log_structure.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(log_structure, config) ⇒ GraphNode

Returns a new instance of GraphNode.



354
355
356
357
# File 'lib/k_log/log_structure.rb', line 354

def initialize(log_structure, config)
  @log_structure = log_structure
  @config = config || OpenStruct.new
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



333
334
335
# File 'lib/k_log/log_structure.rb', line 333

def config
  @config
end

#log_structureObject (readonly)

Returns the value of attribute log_structure.



332
333
334
# File 'lib/k_log/log_structure.rb', line 332

def log_structure
  @log_structure
end

Class Method Details

.for(log_structure, graph, graph_path) ⇒ Object



340
341
342
343
344
345
346
347
348
349
350
351
# File 'lib/k_log/log_structure.rb', line 340

def for(log_structure, graph, graph_path)
  node_config = graph_path.reduce(graph) do |node, name|
    # handling the issue where name was :sleep
    result = node.respond_to?(name) ? node.send(name) : nil

    break null if result.nil?

    result
  end

  new(log_structure, node_config)
end

.nullObject



336
337
338
# File 'lib/k_log/log_structure.rb', line 336

def null
  @null ||= OpenStruct.new
end

Instance Method Details

#columnsObject

table_print compatible configuration for displaying columns for an array



360
361
362
# File 'lib/k_log/log_structure.rb', line 360

def columns
  config.columns
end

#debugObject



437
438
439
440
441
442
443
444
445
446
447
448
449
450
# File 'lib/k_log/log_structure.rb', line 437

def debug
  l = KLog::LogUtil.new(KLog.logger)
  l.kv('columns', columns) if columns
  l.kv('heading', heading) if heading
  l.kv('heading_type', heading_type) if heading_type
  l.kv('filter?', filter?)
  l.kv('take', take)
  l.kv('limited?', limited?)
  l.kv('sort?', sort?)
  l.kv('sort', sort)
  l.kv('skip?', skip?)
  l.kv('pry_at', pry_at)
  l.kv('skip_empty?', skip_empty?)
end

#filter(value) ⇒ Object

Array rows are filtered via this predicate



390
391
392
# File 'lib/k_log/log_structure.rb', line 390

def filter(value)
  config.filter.call(value)
end

#filter?Boolean

Array rows are filtered

Returns:

  • (Boolean)


385
386
387
# File 'lib/k_log/log_structure.rb', line 385

def filter?
  config&.filter.respond_to?(:call)
end

#headingObject

Optional heading for the node



365
366
367
# File 'lib/k_log/log_structure.rb', line 365

def heading
  config.heading
end

#heading_typeObject

Type of heading [:heading, :subheading, :section]



370
371
372
# File 'lib/k_log/log_structure.rb', line 370

def heading_type
  config.heading_type || :section
end

#limited?Boolean

Array rows are limited, see take

Returns:

  • (Boolean)


400
401
402
# File 'lib/k_log/log_structure.rb', line 400

def limited?
  config.take&.is_a?(Integer)
end

#pry_atObject

Useful in complex debug scenarios



420
421
422
# File 'lib/k_log/log_structure.rb', line 420

def pry_at
  config.pry_at || []
end

#pry_at?(section) ⇒ Boolean

Returns:

  • (Boolean)


424
425
426
# File 'lib/k_log/log_structure.rb', line 424

def pry_at?(section)
  pry_at.include?(section)
end

#show_array_countObject



433
434
435
# File 'lib/k_log/log_structure.rb', line 433

def show_array_count
  log_structure.show_array_count
end

#skip?Boolean

Skip this node

Returns:

  • (Boolean)


415
416
417
# File 'lib/k_log/log_structure.rb', line 415

def skip?
  config.skip == true
end

#skip_empty?Boolean

Skip empty array node (my be useful for other nodes, but not yet)

Returns:

  • (Boolean)


429
430
431
# File 'lib/k_log/log_structure.rb', line 429

def skip_empty?
  config.skip_empty == true
end

#sortObject

Use array.sort?



410
411
412
# File 'lib/k_log/log_structure.rb', line 410

def sort
  config.sort
end

#sort?Boolean

Array rows are sorted using .sort

Returns:

  • (Boolean)


405
406
407
# File 'lib/k_log/log_structure.rb', line 405

def sort?
  config&.sort.respond_to?(:call)
end

#takeObject

How any array rows to take



395
396
397
# File 'lib/k_log/log_structure.rb', line 395

def take
  config.take
end

#transform(value) ⇒ Object

Transform node value



380
381
382
# File 'lib/k_log/log_structure.rb', line 380

def transform(value)
  config.transform.call(value)
end

#transform?Boolean

Node data is to be transformed

Returns:

  • (Boolean)


375
376
377
# File 'lib/k_log/log_structure.rb', line 375

def transform?
  config&.transform.respond_to?(:call)
end