Class: SCNR::Introspector::ExecutionFlow

Inherits:
Object
  • Object
show all
Defined in:
lib/scnr/introspector/execution_flow.rb,
lib/scnr/introspector/execution_flow/point.rb,
lib/scnr/introspector/execution_flow/scope.rb

Defined Under Namespace

Classes: Point, Scope

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ ExecutionFlow

Returns a new instance of ExecutionFlow.

Parameters:

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

    Code to #trace.

Options Hash (options):

Raises:



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/scnr/introspector/execution_flow.rb', line 25

def initialize( options = {}, &block )
    options = options.dup

    if (scope = options.delete(:scope)).is_a? ExecutionFlow::Scope
        @scope = scope
    elsif scope.is_a? Hash
        @scope = ExecutionFlow::Scope.new( scope )
    elsif scope.nil?
        @scope = ExecutionFlow::Scope.new
    else
        fail ExecutionFlow::Scope::Error::Invalid
    end

    @points = []

    trace( &block ) if block_given?
end

Instance Attribute Details

#pointsArray<Point> (readonly)

Returns:



13
14
15
# File 'lib/scnr/introspector/execution_flow.rb', line 13

def points
  @points
end

#scopeScope

Returns:



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

def scope
  @scope
end

Class Method Details

.from_rpc_data(h) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/scnr/introspector/execution_flow.rb', line 80

def self.from_rpc_data( h )
    n = self.new

    h.each do |k, v|
        case k
            when 'points'
                n.instance_variable_set( "@#{k}", v.map { |pd| Point.from_rpc_data( pd ) } )

            else
                n.instance_variable_set( "@#{k}", v )
        end
    end

    n
end

Instance Method Details

#to_rpc_dataObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/scnr/introspector/execution_flow.rb', line 60

def to_rpc_data
    data = {}
    instance_variables.each do |iv|
        case iv
            when :@points
                data['points'] = @points.map(&:to_rpc_data)

            when :@scope
                next

        else
            v = instance_variable_get( iv )
            next if !v
            data[iv.to_s.gsub('@','')] = v.to_rpc_data

        end
    end
    data
end

#trace(&block) ⇒ ExecutionFlow

Traces code execution events as points and populates #points.

Parameters:

  • block (Block)

    Code to trace.

Returns:



50
51
52
53
54
55
56
57
58
# File 'lib/scnr/introspector/execution_flow.rb', line 50

def trace( &block )
    TracePoint.new do |tp|
        next if @scope.out?( tp.path )

        @points << create_point_from_trace_point( tp )
    end.enable(&block)

    self
end