Class: SuperDiff::ObjectInspection::Nodes::AsLinesWhenRenderingToLines

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#clone_with, #pretty_print, #render

Constructor Details

#initialize(tree, *args, add_comma: false, collection_bookend: nil, **rest) ⇒ AsLinesWhenRenderingToLines

Returns a new instance of AsLinesWhenRenderingToLines.



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb', line 13

def initialize(
  tree,
  *args,
  add_comma: false,
  collection_bookend: nil,
  **rest
)
  super(tree, *args, **rest)

  @add_comma = add_comma
  @collection_bookend = collection_bookend
end

Class Method Details

.method_nameObject



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

def self.method_name
  :as_lines_when_rendering_to_lines
end

.node_nameObject



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

def self.node_name
  :as_lines_when_rendering_to_lines
end

Instance Method Details

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



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

def render_to_lines(object, type:, indentation_level:)
  lines =
    if block
      render_to_lines_in_subtree(
        object,
        type: type,
        indentation_level: indentation_level,
        disallowed_node_names: %i[line as_lines_when_rendering_to_lines]
      )
    else
      [
        SuperDiff::Line.new(
          type: type,
          indentation_level: indentation_level,
          value: immediate_value.to_s
        )
      ]
    end

  with_collection_bookend_added_to_last_line_in(
    with_add_comma_added_to_last_line_in(lines)
  )
end

#render_to_string(object) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb', line 26

def render_to_string(object)
  # TODO: This happens a lot, can we simplify this?
  string =
    (block ? render_to_string_in_subtree(object) : immediate_value.to_s)

  add_comma? ? string + "," : string
end