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.
Class Method Summary collapse
Instance Method Summary collapse
-
#columns ⇒ Object
table_print compatible configuration for displaying columns for an array.
-
#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(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
-
#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(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
#config ⇒ Object
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 |
.null ⇒ Object
327 328 329 |
# File 'lib/k_log/log_structure.rb', line 327 def null @null ||= OpenStruct.new end |
Instance Method Details
#columns ⇒ Object
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
376 377 378 |
# File 'lib/k_log/log_structure.rb', line 376 def filter? config&.filter.respond_to?(:call) end |
#heading ⇒ Object
Optional heading for the node
356 357 358 |
# File 'lib/k_log/log_structure.rb', line 356 def heading config.heading end |
#heading_type ⇒ Object
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
391 392 393 |
# File 'lib/k_log/log_structure.rb', line 391 def limited? config.take&.is_a?(Integer) end |
#pry_at ⇒ Object
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
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
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)
420 421 422 |
# File 'lib/k_log/log_structure.rb', line 420 def skip_empty? config.skip_empty == true end |
#sort ⇒ Object
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
396 397 398 |
# File 'lib/k_log/log_structure.rb', line 396 def sort? config&.sort.respond_to?(:call) end |
#take ⇒ Object
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
366 367 368 |
# File 'lib/k_log/log_structure.rb', line 366 def transform? config&.transform.respond_to?(:call) end |