class Delfos::MethodLogging::CodeLocation
Attributes
class_method[R]
line_number[R]
method_name[R]
object[R]
Public Class Methods
from_call_site(stack, call_site_binding)
click to toggle source
# File lib/delfos/method_logging/code_location.rb, line 8 def from_call_site(stack, call_site_binding) CallSiteParsing.new(stack, call_site_binding).perform end
from_called(object, called_method, class_method)
click to toggle source
# File lib/delfos/method_logging/code_location.rb, line 12 def from_called(object, called_method, class_method) file, line_number = called_method.source_location return unless file && line_number new(object: object, method_name: called_method.name.to_s, class_method: class_method, file: file, line_number: line_number) end
new(object:, method_name:, class_method:, file:, line_number:)
click to toggle source
# File lib/delfos/method_logging/code_location.rb, line 24 def initialize(object:, method_name:, class_method:, file:, line_number:) @object = object @method_name = method_name @class_method = class_method @line_number = line_number.to_i @file = file end
Public Instance Methods
file()
click to toggle source
# File lib/delfos/method_logging/code_location.rb, line 32 def file relative_filename @file end
klass()
click to toggle source
# File lib/delfos/method_logging/code_location.rb, line 36 def klass object.is_a?(Class) ? object : object.class end
method_definition_file()
click to toggle source
# File lib/delfos/method_logging/code_location.rb, line 40 def method_definition_file relative_filename(method_definition&.first || fallback_method_definition_file) end
method_definition_line()
click to toggle source
# File lib/delfos/method_logging/code_location.rb, line 44 def method_definition_line method_definition&.last&.to_i || fallback_method_definition_line_number end
method_type()
click to toggle source
# File lib/delfos/method_logging/code_location.rb, line 48 def method_type class_method ? "ClassMethod" : "InstanceMethod" end
Private Instance Methods
fallback_method_definition_file()
click to toggle source
# File lib/delfos/method_logging/code_location.rb, line 76 def fallback_method_definition_file @file end
fallback_method_definition_line_number()
click to toggle source
# File lib/delfos/method_logging/code_location.rb, line 80 def fallback_method_definition_line_number 0 end
method_definition()
click to toggle source
# File lib/delfos/method_logging/code_location.rb, line 84 def method_definition @method_definition ||= Patching::MethodCache.find(klass: klass, method_name: method_name, class_method: class_method)&.source_location end
relative_filename(f)
click to toggle source
# File lib/delfos/method_logging/code_location.rb, line 54 def relative_filename(f) return unless f file = f.to_s Delfos.application_directories.map do |d| file = relative_path(file, d) end file end
relative_path(file, dir)
click to toggle source
# File lib/delfos/method_logging/code_location.rb, line 65 def relative_path(file, dir) match = dir.to_s.split("/")[0..-2].join("/") if file[match] file = file.gsub(match, ""). gsub(%r{^/}, "") end file end