Class: SuperDiff::ObjectInspection::Nodes::Base
- Inherits:
-
Object
- Object
- SuperDiff::ObjectInspection::Nodes::Base
- Defined in:
- lib/super_diff/object_inspection/nodes/base.rb
Direct Known Subclasses
Break, Inspection, Nesting, Text, WhenEmpty, WhenMultiline, WhenNonEmpty, WhenSingleline
Instance Method Summary collapse
- #clone_with(tree: @tree, immediate_value: @immediate_value, block: @block) ⇒ Object
-
#evaluate(object, indent_level:, as_single_line:) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
-
#initialize(tree, *args, &block) ⇒ Base
constructor
A new instance of Base.
- #pretty_print(pp) ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(tree, *args, &block) ⇒ Base
Returns a new instance of Base.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/super_diff/object_inspection/nodes/base.rb', line 5 def initialize(tree, *args, &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 end |
Instance Method Details
#clone_with(tree: @tree, immediate_value: @immediate_value, block: @block) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/super_diff/object_inspection/nodes/base.rb', line 18 def clone_with( tree: @tree, immediate_value: @immediate_value, block: @block ) if block self.class.new(tree, &block) else self.class.new(tree, immediate_value) end end |
#evaluate(object, indent_level:, as_single_line:) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument
39 40 41 42 43 44 45 |
# File 'lib/super_diff/object_inspection/nodes/base.rb', line 39 def evaluate(object, indent_level:, as_single_line:) # rubocop:enable Lint/UnusedMethodArgument raise NotImplementedError.new( "Your node must provide an #evaluate method. " + "(Keep in mind #evaluate may be called more than once for a node!)", ) end |
#pretty_print(pp) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/super_diff/object_inspection/nodes/base.rb', line 47 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 |
#type ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/super_diff/object_inspection/nodes/base.rb', line 30 def type self.class.name. sub(/^(.+)::(.+?)$/, '\2'). gsub(/([a-z])([A-Z])/, '\1_\2'). downcase. to_sym end |