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.
-
#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
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
#config ⇒ Object
Returns the value of attribute config.
330 331 332 |
# File 'lib/k_log/log_structure.rb', line 330 def config @config end |
#log_structure ⇒ Object (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 |
.null ⇒ Object
333 334 335 |
# File 'lib/k_log/log_structure.rb', line 333 def null @null ||= OpenStruct.new end |
Instance Method Details
#columns ⇒ Object
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
383 384 385 |
# File 'lib/k_log/log_structure.rb', line 383 def filter? config&.filter.respond_to?(:call) end |
#heading ⇒ Object
Optional heading for the node
363 364 365 |
# File 'lib/k_log/log_structure.rb', line 363 def heading config.heading end |
#heading_type ⇒ Object
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
398 399 400 |
# File 'lib/k_log/log_structure.rb', line 398 def limited? config.take&.is_a?(Integer) end |
#pry_at ⇒ Object
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
422 423 424 |
# File 'lib/k_log/log_structure.rb', line 422 def pry_at?(section) pry_at.include?(section) end |
#show_array_count ⇒ Object
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
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)
427 428 429 |
# File 'lib/k_log/log_structure.rb', line 427 def skip_empty? config.skip_empty == true end |
#sort ⇒ Object
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
403 404 405 |
# File 'lib/k_log/log_structure.rb', line 403 def sort? config&.sort.respond_to?(:call) end |
#take ⇒ Object
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
373 374 375 |
# File 'lib/k_log/log_structure.rb', line 373 def transform? config&.transform.respond_to?(:call) end |