Class: SuperDiff::ObjectInspection::Nodes::Base

Inherits:
Object
  • Object
show all
Extended by:
ImplementationChecks
Includes:
ImplementationChecks
Defined in:
lib/super_diff/object_inspection/nodes/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tree, *args, **options, &block) ⇒ Base

Returns a new instance of Base.



16
17
18
19
20
21
22
23
24
25
26
27
28
# 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

Class Method Details

.method_nameObject



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

def self.method_name
  unimplemented_class_method!
end

.node_nameObject



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

def self.node_name
  unimplemented_class_method!
end

Instance Method Details

#clone_with(tree: @tree, immediate_value: @immediate_value, block: @block, **rest) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# 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) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# 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) ⇒ Object



43
44
45
46
47
48
49
# 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:) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



58
59
60
61
# 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) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



52
53
54
55
# File 'lib/super_diff/object_inspection/nodes/base.rb', line 52

def render_to_string(object)
# rubocop:enable Lint/UnusedMethodArgument
  unimplemented_instance_method!
end