123456789_123456789_123456789_123456789_123456789_

Class: RBS::Test::Tester::MethodCallTester

Relationships & Source Files
Inherits: Object
Defined in: lib/rbs/test/tester.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(self_class, builder, definition, kind:, sample_size:, unchecked_classes:) ⇒ MethodCallTester

[ GitHub ]

  
# File 'lib/rbs/test/tester.rb', line 119

def initialize(self_class, builder, definition, kind:, sample_size:, unchecked_classes:)
  @self_class = self_class
  @definition = definition
  @builder = builder
  @kind = kind
  @sample_size = sample_size
  @unchecked_classes = unchecked_classes
end

Instance Attribute Details

#builder (readonly)

[ GitHub ]

  
# File 'lib/rbs/test/tester.rb', line 114

attr_reader :builder

#definition (readonly)

[ GitHub ]

  
# File 'lib/rbs/test/tester.rb', line 113

attr_reader :definition

#kind (readonly)

[ GitHub ]

  
# File 'lib/rbs/test/tester.rb', line 115

attr_reader :kind

#sample_size (readonly)

[ GitHub ]

  
# File 'lib/rbs/test/tester.rb', line 116

attr_reader :sample_size

#self_class (readonly)

[ GitHub ]

  
# File 'lib/rbs/test/tester.rb', line 112

attr_reader :self_class

#unchecked_classes (readonly)

[ GitHub ]

  
# File 'lib/rbs/test/tester.rb', line 117

attr_reader :unchecked_classes

Instance Method Details

#call(receiver, trace)

[ GitHub ]

  
# File 'lib/rbs/test/tester.rb', line 145

def call(receiver, trace)
  method_name = trace.method_name
  method = definition.methods[method_name]
  if method
    RBS.logger.debug { "Type checking `#{self_class}#{format_method_name(method_name)}`..."}
    errors = check.overloaded_call(method, format_method_name(method_name), trace, errors: [])

    if errors.empty?
      RBS.logger.debug { "No type error detected 👏" }
    else
      RBS.logger.debug { "Detected type error 🚨" }
      raise TypeError.new(errors)
    end
  else
    RBS.logger.error { "Type checking `#{self_class}#{method_name}` call but no method found in definition" }
  end
end

#check

[ GitHub ]

  
# File 'lib/rbs/test/tester.rb', line 132

def check
  @check ||= TypeCheck.new(self_class: self_class, builder: builder, sample_size: sample_size, unchecked_classes: unchecked_classes)
end

#env

[ GitHub ]

  
# File 'lib/rbs/test/tester.rb', line 128

def env
  builder.env
end

#format_method_name(name)

[ GitHub ]

  
# File 'lib/rbs/test/tester.rb', line 136

def format_method_name(name)
  case kind
  when :instance
    "##{name}"
  when :singleton
    ".#{name}"
  end
end