Class: SCNR::Introspector::ExecutionFlow::Point

Inherits:
Object
  • Object
show all
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 Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Point

Returns a new instance of Point.

Parameters:

  • options (Hash) (defaults to: {})


30
31
32
33
34
35
36
# File 'lib/scnr/introspector/execution_flow/point.rb', line 30

def initialize( options = {} )
    options.each do |k, v|
        next if v.nil?

        send( "#{k}=", v )
    end
end

Instance Attribute Details

#class_nameString

Returns Class name containing the point.

Returns:

  • (String)

    Class name containing the point.



19
20
21
# File 'lib/scnr/introspector/execution_flow/point.rb', line 19

def class_name
  @class_name
end

#eventSymbol

Returns Event name.

Returns:

  • (Symbol)

    Event name.



27
28
29
# File 'lib/scnr/introspector/execution_flow/point.rb', line 27

def event
  @event
end

#line_numberInteger?

Returns File line number, ‘nil` if no file is available (i.e. compiled code).

Returns:

  • (Integer, nil)

    File line number, ‘nil` if no file is available (i.e. compiled code).



15
16
17
# File 'lib/scnr/introspector/execution_flow/point.rb', line 15

def line_number
  @line_number
end

#method_nameSymbol

Returns Name of method associated with the #event.

Returns:

  • (Symbol)

    Name of method associated with the #event.



23
24
25
# File 'lib/scnr/introspector/execution_flow/point.rb', line 23

def method_name
  @method_name
end

#pathString?

Returns Path to the source file, ‘nil` if no file is available (i.e. compiled code).

Returns:

  • (String, nil)

    Path to the source file, ‘nil` if no file is available (i.e. compiled code).



11
12
13
# File 'lib/scnr/introspector/execution_flow/point.rb', line 11

def path
  @path
end

Class Method Details

.from_rpc_data(data) ⇒ Object



57
58
59
60
61
# File 'lib/scnr/introspector/execution_flow/point.rb', line 57

def self.from_rpc_data( data )
    n = self.new
    n.marshal_load( data )
    n
end

.from_trace_point(tp) ⇒ Point

Parameters:

  • tp (TracePoint)

    Ruby TracePoint object.

Returns:



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/scnr/introspector/execution_flow/point.rb', line 69

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
    })
end

Instance Method Details

#inspectObject



38
39
40
# File 'lib/scnr/introspector/execution_flow/point.rb', line 38

def inspect
    "#{path}:#{line_number} #{class_name}##{method_name} #{event}"
end

#marshal_dumpObject



42
43
44
45
46
47
# File 'lib/scnr/introspector/execution_flow/point.rb', line 42

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



49
50
51
# File 'lib/scnr/introspector/execution_flow/point.rb', line 49

def marshal_load( h )
    h.each { |k, v| instance_variable_set( "@#{k}", v ) }
end

#to_rpc_dataObject



53
54
55
# File 'lib/scnr/introspector/execution_flow/point.rb', line 53

def to_rpc_data
    marshal_dump
end