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(config) ⇒ GraphNode

Returns a new instance of GraphNode.



346
347
348
# File 'lib/k_log/log_structure.rb', line 346

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

Instance Attribute Details

#configObject

Returns the value of attribute config.



324
325
326
# File 'lib/k_log/log_structure.rb', line 324

def config
  @config
end

Class Method Details

.for(graph, graph_path) ⇒ Object



331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'lib/k_log/log_structure.rb', line 331

def for(graph, graph_path)
  # node_config = graph_path.inject(graph, :send) # (uses deep nesting, but fails when nil is returned) https://stackoverflow.com/questions/15862455/ruby-nested-send
  # node.nil? ? null : node.send(name) || null
  node_config = graph_path.reduce(graph) do |node, name|
    result = node.send(name)

    break null if result.nil?

    result
  end

  new(node_config)
end

.nullObject



327
328
329
# File 'lib/k_log/log_structure.rb', line 327

def null
  @null ||= OpenStruct.new
end

Instance Method Details

#columnsObject

table_print compatible configuration for displaying columns for an array



351
352
353
# File 'lib/k_log/log_structure.rb', line 351

def columns
  config.columns
end

#filter(value) ⇒ Object

Array rows are filtered via this predicate



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

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

#filter?Boolean

Array rows are filtered

Returns:

  • (Boolean)


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

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

#headingObject

Optional heading for the node



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

def heading
  config.heading
end

#heading_typeObject

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



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

def heading_type
  config.heading_type || :section
end

#limited?Boolean

Array rows are limited, see take

Returns:

  • (Boolean)


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

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

#pry_atObject

Useful in complex debug scenarios



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

def pry_at
  config.pry_at || []
end

#pry_at?(section) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#skip?Boolean

Skip this node

Returns:

  • (Boolean)


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

def skip?
  config.skip == true
end

#skip_empty?Boolean

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

Returns:

  • (Boolean)


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

def skip_empty?
  config.skip_empty == true
end

#sortObject

Use array.sort?



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

def sort
  config.sort
end

#sort?Boolean

Array rows are sorted using .sort

Returns:

  • (Boolean)


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

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

#takeObject

How any array rows to take



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

def take
  config.take
end

#transform(value) ⇒ Object

Transform node value



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

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

#transform?Boolean

Node data is to be transformed

Returns:

  • (Boolean)


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

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