class SuperDiff::ObjectInspection::Nodes::Base

Attributes

block[R]
immediate_value[R]
options[R]
tree[R]

Public Class Methods

method_name() click to toggle source
# File lib/super_diff/object_inspection/nodes/base.rb, line 9
def self.method_name
  unimplemented_class_method!
end
new(tree, *args, **options, &block) click to toggle source
# File lib/super_diff/object_inspection/nodes/base.rb, line 16
def initialize(tree, *args, **options, &block)
  if !args.empty? && block
    raise ArgumentError.new(
      "You cannot provide both an immediate value and a lazy value. " +
      "Either pass a block or a positional argument.",
    )
  end

  @tree = tree
  @immediate_value = args.first
  @block = block
  @options = options
end
node_name() click to toggle source
# File lib/super_diff/object_inspection/nodes/base.rb, line 5
def self.node_name
  unimplemented_class_method!
end

Public Instance Methods

clone_with( tree: @tree, immediate_value: @immediate_value, block: @block, **rest ) click to toggle source
# File lib/super_diff/object_inspection/nodes/base.rb, line 30
def clone_with(
  tree: @tree,
  immediate_value: @immediate_value,
  block: @block,
  **rest
)
  if block
    self.class.new(tree, **options, **rest, &block)
  else
    self.class.new(tree, immediate_value, **options, **rest)
  end
end
pretty_print(pp) click to toggle source
# File lib/super_diff/object_inspection/nodes/base.rb, line 63
def pretty_print(pp)
  pp.object_address_group(self) do
    pp.seplist(pretty_print_variables, proc { pp.text "," }) do |name|
      value = instance_variable_get(name)
      pp.breakable " "
      pp.group(1) do
        pp.text name[1..-1].to_s
        pp.text ":"
        pp.breakable
        pp.pp value
      end
    end
  end
end
render(object, preferably_as_lines:, **rest) click to toggle source
# File lib/super_diff/object_inspection/nodes/base.rb, line 43
def render(object, preferably_as_lines:, **rest)
  if options[:as_lines] || preferably_as_lines
    render_to_lines(object, **rest)
  else
    render_to_string(object)
  end
end
render_to_lines(object, type:, indentation_level:) click to toggle source

rubocop:disable Lint/UnusedMethodArgument

# File lib/super_diff/object_inspection/nodes/base.rb, line 58
def render_to_lines(object, type:, indentation_level:)
# rubocop:enable Lint/UnusedMethodArgument
  unimplemented_instance_method!
end
render_to_string(object) click to toggle source

rubocop:disable Lint/UnusedMethodArgument

# File lib/super_diff/object_inspection/nodes/base.rb, line 52
def render_to_string(object)
# rubocop:enable Lint/UnusedMethodArgument
  unimplemented_instance_method!
end

Private Instance Methods

evaluate_block(object) click to toggle source
# File lib/super_diff/object_inspection/nodes/base.rb, line 90
def evaluate_block(object)
  tree.evaluate_block(object, &block)
end
pretty_print_variables() click to toggle source
# File lib/super_diff/object_inspection/nodes/base.rb, line 82
def pretty_print_variables
  if block
    [:"@block"]
  else
    [:"@immediate_value"]
  end
end
render_to_lines_in_subtree( object, type:, indentation_level:, disallowed_node_names: [], **rest ) click to toggle source
# File lib/super_diff/object_inspection/nodes/base.rb, line 100
def render_to_lines_in_subtree(
  object,
  type:,
  indentation_level:,
  disallowed_node_names: [],
  **rest
)
  subtree = InspectionTree.new(
    disallowed_node_names: disallowed_node_names,
  )
  subtree.evaluate_block(object, &block)
  subtree.render_to_lines(
    object,
    type: type,
    indentation_level: indentation_level,
    **rest,
  )
end
render_to_string_in_subtree(object) click to toggle source
# File lib/super_diff/object_inspection/nodes/base.rb, line 94
def render_to_string_in_subtree(object)
  subtree = InspectionTree.new
  subtree.evaluate_block(object, &block)
  subtree.render_to_string(object)
end