Method: Peeky::MethodInfo#infer_default_paramaters
- Defined in:
- lib/peeky/method_info.rb
#infer_default_paramaters ⇒ Object
Infer default paramater values
WARNING: Unit test coverage went from .1 seconds to 30-40 seconds when I first introduced this method.
I now only call TracePoint if I have optional parameters to be inferred.
The tests are now down to 5 seconds, but it highlights the cost of use TracePoint.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/peeky/method_info.rb', line 90 def infer_default_paramaters class_name = @implementation_type == :class_method ? @target_instance.class.name : nil minimalist_method = Peeky::Renderer::MethodCallMinimumParamsRender.new(self, class_name: class_name).render return if minimalist_method.end_with?('=') return unless optional? # TODO: maybe I can use this technique instead and just read the source code # file, line = @focal_method.source_location tracer.enable do # puts grab_source # TODO: minimalist method should be able to handle class methods @target_instance.instance_eval(minimalist_method) if @implementation_type == :method @target_instance.class.instance_eval(minimalist_method) if @implementation_type == :class_method rescue StandardError, LoadError # => e # just print the error for now, we are only attempting to capture the # first call, any errors inside the call cannot be dealt with and should # not be re-raised # red full stop print "\e[31m.\e[0m" # puts minimalist_method # puts e.message end end |