Class: SCNR::Introspector::ExecutionFlow::Point
- Inherits:
-
Object
- Object
- SCNR::Introspector::ExecutionFlow::Point
- Defined in:
- lib/scnr/introspector/execution_flow/point.rb
Overview
Trace point, similar in function to a native Ruby TracePoint. Points to a code execution #event.
Instance Attribute Summary collapse
-
#class_name ⇒ String
Class name containing the point.
-
#event ⇒ Symbol
Event name.
-
#file_contents ⇒ Object
Returns the value of attribute file_contents.
-
#line_number ⇒ Integer?
File line number, ‘nil` if no file is available (i.e. compiled code).
-
#method_name ⇒ Symbol
Name of method associated with the #event.
-
#path ⇒ String?
Path to the source file, ‘nil` if no file is available (i.e. compiled code).
-
#source ⇒ Object
Returns the value of attribute source.
Class Method Summary collapse
- .from_rpc_data(data) ⇒ Object
- .from_trace_point(tp) ⇒ Point
- .source_line(path, line) ⇒ Object
- .source_line_mutex(&block) ⇒ Object
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Point
constructor
A new instance of Point.
- #inspect ⇒ Object
- #marshal_dump ⇒ Object
- #marshal_load(h) ⇒ Object
- #to_rpc_data ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Point
Returns a new instance of Point.
35 36 37 38 39 40 41 |
# File 'lib/scnr/introspector/execution_flow/point.rb', line 35 def initialize( = {} ) .each do |k, v| next if v.nil? send( "#{k}=", v ) end end |
Instance Attribute Details
#class_name ⇒ String
Returns Class name containing the point.
21 22 23 |
# File 'lib/scnr/introspector/execution_flow/point.rb', line 21 def class_name @class_name end |
#event ⇒ Symbol
Returns Event name.
29 30 31 |
# File 'lib/scnr/introspector/execution_flow/point.rb', line 29 def event @event end |
#file_contents ⇒ Object
Returns the value of attribute file_contents.
32 33 34 |
# File 'lib/scnr/introspector/execution_flow/point.rb', line 32 def file_contents @file_contents end |
#line_number ⇒ Integer?
Returns File line number, ‘nil` if no file is available (i.e. compiled code).
17 18 19 |
# File 'lib/scnr/introspector/execution_flow/point.rb', line 17 def line_number @line_number end |
#method_name ⇒ Symbol
Returns Name of method associated with the #event.
25 26 27 |
# File 'lib/scnr/introspector/execution_flow/point.rb', line 25 def method_name @method_name end |
#path ⇒ String?
Returns Path to the source file, ‘nil` if no file is available (i.e. compiled code).
13 14 15 |
# File 'lib/scnr/introspector/execution_flow/point.rb', line 13 def path @path end |
#source ⇒ Object
Returns the value of attribute source.
31 32 33 |
# File 'lib/scnr/introspector/execution_flow/point.rb', line 31 def source @source end |
Class Method Details
.from_rpc_data(data) ⇒ Object
62 63 64 65 66 |
# File 'lib/scnr/introspector/execution_flow/point.rb', line 62 def self.from_rpc_data( data ) n = self.new n.marshal_load( data ) n end |
.from_trace_point(tp) ⇒ Point
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/scnr/introspector/execution_flow/point.rb', line 74 def from_trace_point( tp ) defined_class = (tp.defined_class.is_a?( Class ) || tp.defined_class.is_a?( Module ) ? tp.defined_class.name : tp.defined_class.class.name) new({ path: tp.path, line_number: tp.lineno, class_name: defined_class, method_name: tp.method_id, event: tp.event, source: source_line( tp.path, tp.lineno ), file_contents: IO.read( tp.path ) }) end |
.source_line(path, line) ⇒ Object
94 95 96 97 98 99 100 101 102 |
# File 'lib/scnr/introspector/execution_flow/point.rb', line 94 def source_line( path, line ) return if !path || !line source_line_mutex do @@lines ||= {} @@lines[path] ||= IO.readlines( path ) @@lines[path][line-1] end end |
.source_line_mutex(&block) ⇒ Object
90 91 92 |
# File 'lib/scnr/introspector/execution_flow/point.rb', line 90 def source_line_mutex( &block ) (@mutex ||= Mutex.new).synchronize( &block ) end |
Instance Method Details
#inspect ⇒ Object
43 44 45 |
# File 'lib/scnr/introspector/execution_flow/point.rb', line 43 def inspect "#{path}:#{line_number} #{class_name}##{method_name} #{event}" end |
#marshal_dump ⇒ Object
47 48 49 50 51 52 |
# File 'lib/scnr/introspector/execution_flow/point.rb', line 47 def marshal_dump instance_variables.inject( {} ) do |h, iv| h[iv.to_s.gsub('@','')] = instance_variable_get( iv ) h end end |
#marshal_load(h) ⇒ Object
54 55 56 |
# File 'lib/scnr/introspector/execution_flow/point.rb', line 54 def marshal_load( h ) h.each { |k, v| instance_variable_set( "@#{k}", v ) } end |
#to_rpc_data ⇒ Object
58 59 60 |
# File 'lib/scnr/introspector/execution_flow/point.rb', line 58 def to_rpc_data marshal_dump end |