class Delfos::MethodLogging::CallSiteParsing
Constants
- METHOD_NAME_REGEX
- STACK_OFFSET
This magic number is based on the implementation within this file. If the line with `call_site_binding.of_caller(
stack_index
+STACK_OFFSET
).receiver` is moved up or down the call stack a test fails and we have to change `STACK_OFFSET`
Attributes
call_site_binding[R]
stack[R]
Public Class Methods
new(stack, call_site_binding, stack_offset: nil)
click to toggle source
# File lib/delfos/method_logging/call_site_parsing.rb, line 14 def initialize(stack, call_site_binding, stack_offset: nil) @stack = stack @call_site_binding = call_site_binding @stack_offset = stack_offset end
Public Instance Methods
perform()
click to toggle source
# File lib/delfos/method_logging/call_site_parsing.rb, line 20 def perform file, line_number, method_name = method_details return unless current && file && line_number && method_name CodeLocation.new(object: object, method_name: method_name.to_s, class_method: class_method, file: file, line_number: line_number) end
Private Instance Methods
class_method()
click to toggle source
# File lib/delfos/method_logging/call_site_parsing.rb, line 33 def class_method object.is_a? Module end
current()
click to toggle source
# File lib/delfos/method_logging/call_site_parsing.rb, line 37 def current stack.detect do |s| file = s.split(":")[0] Delfos::MethodLogging.include_file?(file) end end
method_details()
click to toggle source
# File lib/delfos/method_logging/call_site_parsing.rb, line 58 def method_details return unless current file, line_number, rest, more = current.split(":") rest = more.nil? ? rest : "#{rest}:#{more}" method_name = rest.match(METHOD_NAME_REGEX)&.[](1) return unless method_name && file && line_number method_name = method_name.delete("`") method_name = method_name.delete("'") [file, line_number.to_i, method_name] end
object()
click to toggle source
# File lib/delfos/method_logging/call_site_parsing.rb, line 44 def object @object ||= call_site_binding.of_caller(stack_index + stack_offset).receiver end
stack_index()
click to toggle source
# File lib/delfos/method_logging/call_site_parsing.rb, line 52 def stack_index stack.index { |c| c == current } end
stack_offset()
click to toggle source
# File lib/delfos/method_logging/call_site_parsing.rb, line 48 def stack_offset @stack_offset ||= STACK_OFFSET end