Class: KLog::LogStructure::GraphNode
- Inherits:
-
Object
- Object
- KLog::LogStructure::GraphNode
- Defined in:
- lib/k_log/log_structure.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#log_structure ⇒ Object
readonly
Returns the value of attribute log_structure.
Class Method Summary collapse
Instance Method Summary collapse
-
#columns ⇒ Object
table_print compatible configuration for displaying columns for an array.
- #debug ⇒ Object
-
#filter(value) ⇒ Object
Array rows are filtered via this predicate.
-
#filter? ⇒ Boolean
Array rows are filtered.
-
#heading ⇒ Object
Optional heading for the node.
-
#heading_type ⇒ Object
Type of heading [:heading, :subheading, :section].
-
#initialize(log_structure, config) ⇒ GraphNode
constructor
A new instance of GraphNode.
-
#limited? ⇒ Boolean
Array rows are limited, see take.
-
#pry_at ⇒ Object
Useful in complex debug scenarios.
- #pry_at?(section) ⇒ Boolean
- #show_array_count ⇒ Object
-
#skip? ⇒ Boolean
Skip this node.
-
#skip_empty? ⇒ Boolean
Skip empty array node (my be useful for other nodes, but not yet).
-
#sort ⇒ Object
Use array.sort?.
-
#sort? ⇒ Boolean
Array rows are sorted using .sort.
-
#take ⇒ Object
How any array rows to take.
-
#transform(value) ⇒ Object
Transform node value.
-
#transform? ⇒ Boolean
Node data is to be transformed.
Constructor Details
#initialize(log_structure, config) ⇒ GraphNode
355 356 357 358 |
# File 'lib/k_log/log_structure.rb', line 355 def initialize(log_structure, config) @log_structure = log_structure @config = config || OpenStruct.new end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
332 333 334 |
# File 'lib/k_log/log_structure.rb', line 332 def config @config end |
#log_structure ⇒ Object (readonly)
Returns the value of attribute log_structure.
331 332 333 |
# File 'lib/k_log/log_structure.rb', line 331 def log_structure @log_structure end |
Class Method Details
.for(log_structure, graph, graph_path) ⇒ Object
339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
# File 'lib/k_log/log_structure.rb', line 339 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 # puts node_config new(log_structure, node_config) end |
.null ⇒ Object
335 336 337 |
# File 'lib/k_log/log_structure.rb', line 335 def null @null ||= OpenStruct.new end |
Instance Method Details
#columns ⇒ Object
table_print compatible configuration for displaying columns for an array
361 362 363 |
# File 'lib/k_log/log_structure.rb', line 361 def columns config.columns end |
#debug ⇒ Object
438 439 440 441 442 443 444 445 446 447 448 449 450 451 |
# File 'lib/k_log/log_structure.rb', line 438 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
391 392 393 |
# File 'lib/k_log/log_structure.rb', line 391 def filter(value) config.filter.call(value) end |
#filter? ⇒ Boolean
Array rows are filtered
386 387 388 |
# File 'lib/k_log/log_structure.rb', line 386 def filter? config&.filter.respond_to?(:call) end |
#heading ⇒ Object
Optional heading for the node
366 367 368 |
# File 'lib/k_log/log_structure.rb', line 366 def heading config.heading end |
#heading_type ⇒ Object
Type of heading [:heading, :subheading, :section]
371 372 373 |
# File 'lib/k_log/log_structure.rb', line 371 def heading_type config.heading_type || :section end |
#limited? ⇒ Boolean
Array rows are limited, see take
401 402 403 |
# File 'lib/k_log/log_structure.rb', line 401 def limited? config.take&.is_a?(Integer) end |
#pry_at ⇒ Object
Useful in complex debug scenarios
421 422 423 |
# File 'lib/k_log/log_structure.rb', line 421 def pry_at config.pry_at || [] end |
#pry_at?(section) ⇒ Boolean
425 426 427 |
# File 'lib/k_log/log_structure.rb', line 425 def pry_at?(section) pry_at.include?(section) end |
#show_array_count ⇒ Object
434 435 436 |
# File 'lib/k_log/log_structure.rb', line 434 def show_array_count log_structure.show_array_count end |
#skip? ⇒ Boolean
Skip this node
416 417 418 |
# File 'lib/k_log/log_structure.rb', line 416 def skip? config.skip == true end |
#skip_empty? ⇒ Boolean
Skip empty array node (my be useful for other nodes, but not yet)
430 431 432 |
# File 'lib/k_log/log_structure.rb', line 430 def skip_empty? config.skip_empty == true end |
#sort ⇒ Object
Use array.sort?
411 412 413 |
# File 'lib/k_log/log_structure.rb', line 411 def sort config.sort end |
#sort? ⇒ Boolean
Array rows are sorted using .sort
406 407 408 |
# File 'lib/k_log/log_structure.rb', line 406 def sort? config&.sort.respond_to?(:call) end |
#take ⇒ Object
How any array rows to take
396 397 398 |
# File 'lib/k_log/log_structure.rb', line 396 def take config.take end |
#transform(value) ⇒ Object
Transform node value
381 382 383 |
# File 'lib/k_log/log_structure.rb', line 381 def transform(value) config.transform.call(value) end |
#transform? ⇒ Boolean
Node data is to be transformed
376 377 378 |
# File 'lib/k_log/log_structure.rb', line 376 def transform? config&.transform.respond_to?(:call) end |