Class: Delfos::MethodLogging::CodeLocation
- Inherits:
-
Object
- Object
- Delfos::MethodLogging::CodeLocation
- Defined in:
- lib/delfos/method_logging/code_location.rb
Instance Attribute Summary collapse
-
#class_method ⇒ Object
readonly
Returns the value of attribute class_method.
-
#line_number ⇒ Object
readonly
Returns the value of attribute line_number.
-
#method_name ⇒ Object
readonly
Returns the value of attribute method_name.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Class Method Summary collapse
- .from_call_site(stack, call_site_binding) ⇒ Object
- .from_called(object, called_method, class_method) ⇒ Object
Instance Method Summary collapse
- #file ⇒ Object
-
#initialize(object:, method_name:, class_method:, file:, line_number:) ⇒ CodeLocation
constructor
A new instance of CodeLocation.
- #klass ⇒ Object
- #method_definition_file ⇒ Object
- #method_definition_line ⇒ Object
- #method_type ⇒ Object
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_method ⇒ Object (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_number ⇒ Object (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_name ⇒ Object (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 |
#object ⇒ Object (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
#file ⇒ Object
32 33 34 |
# File 'lib/delfos/method_logging/code_location.rb', line 32 def file relative_filename @file end |
#klass ⇒ Object
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_file ⇒ Object
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_line ⇒ Object
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_type ⇒ Object
48 49 50 |
# File 'lib/delfos/method_logging/code_location.rb', line 48 def method_type class_method ? "ClassMethod" : "InstanceMethod" end |