Class: SuperDiff::Core::InspectionTreeNodes::Base

Inherits:
Object
  • Object
show all
Extended by:
SuperDiff::Core::ImplementationChecks
Includes:
SuperDiff::Core::ImplementationChecks
Defined in:
lib/super_diff/core/inspection_tree_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.



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/super_diff/core/inspection_tree_nodes/base.rb', line 18

def initialize(tree, *args, **options, &block)
  if !args.empty? && block
    raise ArgumentError, '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



11
12
13
# File 'lib/super_diff/core/inspection_tree_nodes/base.rb', line 11

def self.method_name
  unimplemented_class_method!
end

.node_nameObject



7
8
9
# File 'lib/super_diff/core/inspection_tree_nodes/base.rb', line 7

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/core/inspection_tree_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/core/inspection_tree_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..].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/core/inspection_tree_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/core/inspection_tree_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/core/inspection_tree_nodes/base.rb', line 52

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