Class: Delfos::MethodLogging::CodeLocation

Inherits:
Object
  • Object
show all
Defined in:
lib/delfos/method_logging/code_location.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object:, method_name:, class_method:, file:, line_number:) ⇒ CodeLocation

Returns a new instance of CodeLocation.



24
25
26
27
28
29
30
# 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

Instance Attribute Details

#class_methodObject (readonly)

Returns the value of attribute class_method.



22
23
24
# File 'lib/delfos/method_logging/code_location.rb', line 22

def class_method
  @class_method
end

#line_numberObject (readonly)

Returns the value of attribute line_number.



22
23
24
# File 'lib/delfos/method_logging/code_location.rb', line 22

def line_number
  @line_number
end

#method_nameObject (readonly)

Returns the value of attribute method_name.



22
23
24
# File 'lib/delfos/method_logging/code_location.rb', line 22

def method_name
  @method_name
end

#objectObject (readonly)

Returns the value of attribute object.



22
23
24
# File 'lib/delfos/method_logging/code_location.rb', line 22

def object
  @object
end

Class Method Details

.from_call_site(stack, call_site_binding) ⇒ Object



8
9
10
# 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) ⇒ Object



12
13
14
15
16
17
18
# 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

Instance Method Details

#fileObject



32
33
34
# File 'lib/delfos/method_logging/code_location.rb', line 32

def file
  relative_filename @file
end

#klassObject



36
37
38
# File 'lib/delfos/method_logging/code_location.rb', line 36

def klass
  object.is_a?(Class) ? object : object.class
end

#method_definition_fileObject



40
41
42
# 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_lineObject



44
45
46
# 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_typeObject



48
49
50
# File 'lib/delfos/method_logging/code_location.rb', line 48

def method_type
  class_method ? "ClassMethod" : "InstanceMethod"
end