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.



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

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

Instance Attribute Details

#configObject

Returns the value of attribute config.



330
331
332
# File 'lib/k_log/log_structure.rb', line 330

def config
  @config
end

#log_structureObject (readonly)

Returns the value of attribute log_structure.



329
330
331
# File 'lib/k_log/log_structure.rb', line 329

def log_structure
  @log_structure
end

Class Method Details

.for(log_structure, graph, graph_path) ⇒ Object



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

def for(log_structure, 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(log_structure, node_config)
end

.nullObject



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

def null
  @null ||= OpenStruct.new
end

Instance Method Details

#columnsObject

table_print compatible configuration for displaying columns for an array



358
359
360
# File 'lib/k_log/log_structure.rb', line 358

def columns
  config.columns
end

#filter(value) ⇒ Object

Array rows are filtered via this predicate



388
389
390
# File 'lib/k_log/log_structure.rb', line 388

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

#filter?Boolean

Array rows are filtered

Returns:

  • (Boolean)


383
384
385
# File 'lib/k_log/log_structure.rb', line 383

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

#headingObject

Optional heading for the node



363
364
365
# File 'lib/k_log/log_structure.rb', line 363

def heading
  config.heading
end

#heading_typeObject

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



368
369
370
# File 'lib/k_log/log_structure.rb', line 368

def heading_type
  config.heading_type || :section
end

#limited?Boolean

Array rows are limited, see take

Returns:

  • (Boolean)


398
399
400
# File 'lib/k_log/log_structure.rb', line 398

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

#pry_atObject

Useful in complex debug scenarios



418
419
420
# File 'lib/k_log/log_structure.rb', line 418

def pry_at
  config.pry_at || []
end

#pry_at?(section) ⇒ Boolean

Returns:

  • (Boolean)


422
423
424
# File 'lib/k_log/log_structure.rb', line 422

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

#show_array_countObject



431
432
433
# File 'lib/k_log/log_structure.rb', line 431

def show_array_count
  log_structure.show_array_count
end

#skip?Boolean

Skip this node

Returns:

  • (Boolean)


413
414
415
# File 'lib/k_log/log_structure.rb', line 413

def skip?
  config.skip == true
end

#skip_empty?Boolean

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

Returns:

  • (Boolean)


427
428
429
# File 'lib/k_log/log_structure.rb', line 427

def skip_empty?
  config.skip_empty == true
end

#sortObject

Use array.sort?



408
409
410
# File 'lib/k_log/log_structure.rb', line 408

def sort
  config.sort
end

#sort?Boolean

Array rows are sorted using .sort

Returns:

  • (Boolean)


403
404
405
# File 'lib/k_log/log_structure.rb', line 403

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

#takeObject

How any array rows to take



393
394
395
# File 'lib/k_log/log_structure.rb', line 393

def take
  config.take
end

#transform(value) ⇒ Object

Transform node value



378
379
380
# File 'lib/k_log/log_structure.rb', line 378

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

#transform?Boolean

Node data is to be transformed

Returns:

  • (Boolean)


373
374
375
# File 'lib/k_log/log_structure.rb', line 373

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