Class: SuperDiff::ObjectInspection::Nodes::AsLinesWhenRenderingToLines
- Defined in:
- lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(tree, *args, add_comma: false, collection_bookend: nil, **rest) ⇒ AsLinesWhenRenderingToLines
constructor
A new instance of AsLinesWhenRenderingToLines.
- #render_to_lines(object, type:, indentation_level:) ⇒ Object
- #render_to_string(object) ⇒ Object
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_name ⇒ Object
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_name ⇒ Object
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
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb', line 42 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: [ :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 33 34 35 36 37 38 39 40 |
# 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 = if block render_to_string_in_subtree(object) else immediate_value.to_s end if add_comma? string + "," else string end end |