Class: SuperDiff::ObjectInspection::Nodes::Inspection

Inherits:
Base
  • Object
show all
Defined in:
lib/super_diff/object_inspection/nodes/inspection.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#clone_with, #initialize, #pretty_print, #render

Constructor Details

This class inherits a constructor from SuperDiff::ObjectInspection::Nodes::Base

Class Method Details

.method_nameObject



9
10
11
# File 'lib/super_diff/object_inspection/nodes/inspection.rb', line 9

def self.method_name
  :add_inspection_of
end

.node_nameObject



5
6
7
# File 'lib/super_diff/object_inspection/nodes/inspection.rb', line 5

def self.node_name
  :inspection
end

Instance Method Details

#render_to_lines(object, type:, indentation_level:) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/super_diff/object_inspection/nodes/inspection.rb', line 31

def render_to_lines(object, type:, indentation_level:)
  value =
    if block
      evaluate_block(object)
    else
      immediate_value
    end

  SuperDiff::RecursionGuard.
    guarding_recursion_of(value) do |already_seen|
      if already_seen
        [
          SuperDiff::Line.new(
            type: type,
            indentation_level: indentation_level,
            value: SuperDiff::RecursionGuard::PLACEHOLDER,
          ),
        ]
      else
        SuperDiff.inspect_object(
          value,
          as_lines: true,
          type: type,
          indentation_level: indentation_level,
        )
      end
    end
end

#render_to_string(object) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/super_diff/object_inspection/nodes/inspection.rb', line 13

def render_to_string(object)
  value =
    if block
      evaluate_block(object)
    else
      immediate_value
    end

  SuperDiff::RecursionGuard.
    guarding_recursion_of(value) do |already_seen|
      if already_seen
        SuperDiff::RecursionGuard::PLACEHOLDER
      else
        SuperDiff.inspect_object(value, as_lines: false)
      end
    end
end