source_route 0.0.9 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/README.md +7 -0
 - data/examples/callback_in_activesupport.rb +34 -0
 - data/lib/source_route.rb +3 -1
 - data/lib/source_route/formats/html.rb +2 -1
 - data/lib/source_route/formats/html_template.slim +29 -10
 - data/lib/source_route/{tp_result.rb → generate_result.rb} +4 -3
 - data/lib/source_route/tp_result_chain.rb +61 -0
 - data/lib/source_route/version.rb +1 -1
 - data/lib/source_route/wrapper.rb +10 -21
 - data/test/source_route_test.rb +35 -19
 - data/test/tp_filter_test.rb +1 -1
 - metadata +5 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 3a497dac48db0ce73092b5fd0b1bff7a3d43b017
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 5008e83d2a398c35c5fc0a6dc379a19d2641ed53
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: b751bcd35cd72c63133c4367e57d15ae26929084c70c372afe07ca2ec8e35db78f4ad5e94aa8504cb17b50d0d8d20d10fe5e741b77ee2e5a53f8fbd8209908ed
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: bbd3f567b24261dee0a075fb1a2e180eae2cd49761a10fca7eefdf474a5911b07a29c7088bbaae68b4926e57d7b21719e03b8ee3d17ab14d69dffcafe56e9fe9
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -77,4 +77,11 @@ see more usage in examples. 
     | 
|
| 
       77 
77 
     | 
    
         | 
| 
       78 
78 
     | 
    
         
             
            ### TODO
         
     | 
| 
       79 
79 
     | 
    
         | 
| 
      
 80 
     | 
    
         
            +
            Hide defined class filter. Add vertical timeline.
         
     | 
| 
      
 81 
     | 
    
         
            +
             
     | 
| 
      
 82 
     | 
    
         
            +
            Add TpResults and GenerateResult(moved from TpResult) class.
         
     | 
| 
      
 83 
     | 
    
         
            +
            ( http://tympanus.net/codrops/2013/05/02/vertical-timeline/
         
     | 
| 
      
 84 
     | 
    
         
            +
            http://stackoverflow.com/questions/20896240/responsive-timeline-ui-with-bootstrap3)
         
     | 
| 
      
 85 
     | 
    
         
            +
             
     | 
| 
      
 86 
     | 
    
         
            +
             
     | 
| 
       80 
87 
     | 
    
         
             
            Add debug option to provider more verbose messages of what has happened
         
     | 
| 
         @@ -0,0 +1,34 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'active_support/callbacks'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require 'source_route'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            SourceRoute.enable do
         
     | 
| 
      
 6 
     | 
    
         
            +
              event :call, :return
         
     | 
| 
      
 7 
     | 
    
         
            +
              defined_class 'ActiveSupport::Callbacks', 'PersonRecord'
         
     | 
| 
      
 8 
     | 
    
         
            +
              method_id :base_save, :saving_message, :callback
         
     | 
| 
      
 9 
     | 
    
         
            +
              result_config.import_return_to_call = true
         
     | 
| 
      
 10 
     | 
    
         
            +
            end
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            class Record
         
     | 
| 
      
 13 
     | 
    
         
            +
              include ActiveSupport::Callbacks
         
     | 
| 
      
 14 
     | 
    
         
            +
              define_callbacks :save
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              def base_save
         
     | 
| 
      
 17 
     | 
    
         
            +
                run_callbacks :save do
         
     | 
| 
      
 18 
     | 
    
         
            +
                  puts "- save"
         
     | 
| 
      
 19 
     | 
    
         
            +
                end
         
     | 
| 
      
 20 
     | 
    
         
            +
              end
         
     | 
| 
      
 21 
     | 
    
         
            +
            end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
            class PersonRecord < Record
         
     | 
| 
      
 24 
     | 
    
         
            +
              set_callback :save, :before, :saving_message
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
              def saving_message
         
     | 
| 
      
 27 
     | 
    
         
            +
                puts "saving..."
         
     | 
| 
      
 28 
     | 
    
         
            +
              end
         
     | 
| 
      
 29 
     | 
    
         
            +
            end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
            person = PersonRecord.new
         
     | 
| 
      
 32 
     | 
    
         
            +
            person.base_save
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
            SourceRoute.build_html_output
         
     | 
    
        data/lib/source_route.rb
    CHANGED
    
    | 
         @@ -1,12 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'ostruct'
         
     | 
| 
       2 
2 
     | 
    
         
             
            require 'logger'
         
     | 
| 
       3 
3 
     | 
    
         
             
            require 'singleton'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'forwardable'
         
     | 
| 
       4 
5 
     | 
    
         | 
| 
       5 
6 
     | 
    
         
             
            require 'awesome_print'
         
     | 
| 
       6 
7 
     | 
    
         | 
| 
       7 
8 
     | 
    
         
             
            require "source_route/version"
         
     | 
| 
       8 
9 
     | 
    
         
             
            require "source_route/wrapper"
         
     | 
| 
       9 
     | 
    
         
            -
            require "source_route/ 
     | 
| 
      
 10 
     | 
    
         
            +
            require "source_route/generate_result"
         
     | 
| 
      
 11 
     | 
    
         
            +
            require "source_route/tp_result_chain"
         
     | 
| 
       10 
12 
     | 
    
         
             
            require "source_route/tp_filter"
         
     | 
| 
       11 
13 
     | 
    
         | 
| 
       12 
14 
     | 
    
         
             
            module SourceRoute
         
     | 
| 
         @@ -13,7 +13,8 @@ module SourceRoute 
     | 
|
| 
       13 
13 
     | 
    
         
             
                    filename = result_config[:filename] || "#{Time.now.strftime('%H%M')}-source-route.html"
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
       15 
15 
     | 
    
         
             
                    if result_config.import_return_to_call and wrapper.condition.has_call_and_return_event
         
     | 
| 
       16 
     | 
    
         
            -
                      wrapper. 
     | 
| 
      
 16 
     | 
    
         
            +
                      wrapper.import_return_value_to_call_chain
         
     | 
| 
      
 17 
     | 
    
         
            +
                      wrapper.order_call_chain
         
     | 
| 
       17 
18 
     | 
    
         
             
                    end
         
     | 
| 
       18 
19 
     | 
    
         
             
                    html_output_str = slim_template.render(wrapper)
         
     | 
| 
       19 
20 
     | 
    
         
             
                    File.open(filename, 'w') do |f|
         
     | 
| 
         @@ -6,9 +6,15 @@ html 
     | 
|
| 
       6 
6 
     | 
    
         
             
                script src="http://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"
         
     | 
| 
       7 
7 
     | 
    
         
             
                script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
      
 9 
     | 
    
         
            +
                css:
         
     | 
| 
      
 10 
     | 
    
         
            +
                  .call-level-1 {}
         
     | 
| 
      
 11 
     | 
    
         
            +
                  .call-level-2 { margin-left: 50px }
         
     | 
| 
      
 12 
     | 
    
         
            +
                  .call-level-3 { margin-left: 100px }
         
     | 
| 
      
 13 
     | 
    
         
            +
                  .call-level-4 { margin-left: 150px }
         
     | 
| 
       9 
14 
     | 
    
         
             
              body(ng-app="SourceRoute" ng-controller="MainCtrl")
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
       10 
16 
     | 
    
         
             
                ruby:
         
     | 
| 
       11 
     | 
    
         
            -
                  local_trace_data = @ 
     | 
| 
      
 17 
     | 
    
         
            +
                  local_trace_data = @tp_result_chain.map do |tp_result|
         
     | 
| 
       12 
18 
     | 
    
         
             
                    if tp_result.key?(:defined_class)
         
     | 
| 
       13 
19 
     | 
    
         
             
                      tp_result[:defined_class] = tp_result[:defined_class].inspect
         
     | 
| 
       14 
20 
     | 
    
         
             
                      tp_result[:return_value] = tp_result[:return_value].inspect if tp_result.key?(:return_value)
         
     | 
| 
         @@ -25,10 +31,10 @@ html 
     | 
|
| 
       25 
31 
     | 
    
         
             
                  .container
         
     | 
| 
       26 
32 
     | 
    
         
             
                    .container-fluid
         
     | 
| 
       27 
33 
     | 
    
         
             
                      .navbar-header
         
     | 
| 
       28 
     | 
    
         
            -
                        a.navbar-brand(href="#" ng-click="resetTraceFilter()") ALL
         
     | 
| 
      
 34 
     | 
    
         
            +
                        a.navbar-brand(href="#" ng-click="::resetTraceFilter()") ALL
         
     | 
| 
       29 
35 
     | 
    
         
             
                      ul.nav.navbar-nav
         
     | 
| 
       30 
36 
     | 
    
         
             
                        li(ng-repeat="event in tpEvents" ng-class="{active: event == traceFilter.event}")
         
     | 
| 
       31 
     | 
    
         
            -
                          a(href="#" ng-click="traceFilter.event = event" ng-bind="event")
         
     | 
| 
      
 37 
     | 
    
         
            +
                          a(href="#" ng-click="traceFilter.event = event" ng-bind="::event")
         
     | 
| 
       32 
38 
     | 
    
         
             
                      ul.nav.navbar-nav.navbar-right
         
     | 
| 
       33 
39 
     | 
    
         
             
                        li
         
     | 
| 
       34 
40 
     | 
    
         
             
                          a(disabled)
         
     | 
| 
         @@ -42,17 +48,17 @@ html 
     | 
|
| 
       42 
48 
     | 
    
         
             
                    .row
         
     | 
| 
       43 
49 
     | 
    
         
             
                      .left-info.col-sm-4
         
     | 
| 
       44 
50 
     | 
    
         
             
                        .btn-group-vertical
         
     | 
| 
       45 
     | 
    
         
            -
                          button.btn.btn-default(ng-repeat="klass in definedClasses"
         
     | 
| 
      
 51 
     | 
    
         
            +
                          button.btn.btn-default(ng-repeat="klass in ::definedClasses"
         
     | 
| 
       46 
52 
     | 
    
         
             
                            ng-click="traceFilter.defined_class = klass" style="height: 60px")
         
     | 
| 
       47 
53 
     | 
    
         
             
                            span(ng-bind="klass")
         
     | 
| 
       48 
     | 
    
         
            -
                      .traces.center-info.col-sm- 
     | 
| 
       49 
     | 
    
         
            -
                        .trace.well.well-lg(ng-repeat="trace in traces | filter:traceFilter:true" 
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
      
 54 
     | 
    
         
            +
                      .traces.center-info.col-sm-8(ng-class="{{traceFilter.event}}")
         
     | 
| 
      
 55 
     | 
    
         
            +
                        .trace.well.well-lg.call-level.call-level(ng-repeat="trace in traces | filter:traceFilter:true"
         
     | 
| 
      
 56 
     | 
    
         
            +
                          ng-class="callLevelClass(trace)")
         
     | 
| 
       51 
57 
     | 
    
         
             
                          .header(ng-click="showMoreDetail = !showMoreDetail")
         
     | 
| 
       52 
58 
     | 
    
         
             
                            span(ng-bind="trace.defined_class")
         
     | 
| 
       53 
59 
     | 
    
         
             
                            span
         
     | 
| 
       54 
60 
     | 
    
         
             
                              | .
         
     | 
| 
       55 
     | 
    
         
            -
                             
     | 
| 
      
 61 
     | 
    
         
            +
                            mark.method-value(ng-bind="trace.method_id")
         
     | 
| 
       56 
62 
     | 
    
         
             
                            / workaround for return_value is 'false' and return_value always to be string when existed
         
     | 
| 
       57 
63 
     | 
    
         
             
                            div(ng-if="isIncludeReturnValue")
         
     | 
| 
       58 
64 
     | 
    
         
             
                              span
         
     | 
| 
         @@ -66,7 +72,7 @@ html 
     | 
|
| 
       66 
72 
     | 
    
         
             
                                span<>(ng-bind="key")
         
     | 
| 
       67 
73 
     | 
    
         
             
                                span<>
         
     | 
| 
       68 
74 
     | 
    
         
             
                                  | =>
         
     | 
| 
       69 
     | 
    
         
            -
                                /  
     | 
| 
      
 75 
     | 
    
         
            +
                                / ? could inspect repaire it ?
         
     | 
| 
       70 
76 
     | 
    
         
             
                                span<>(ng-bind="value || 'null'")
         
     | 
| 
       71 
77 
     | 
    
         
             
                            .ins-vars.well.well-sm(ng-if="trace.instance_var" style="color: blue")
         
     | 
| 
       72 
78 
     | 
    
         
             
                              span Instance Var
         
     | 
| 
         @@ -75,10 +81,15 @@ html 
     | 
|
| 
       75 
81 
     | 
    
         
             
                                span<>
         
     | 
| 
       76 
82 
     | 
    
         
             
                                  | =>
         
     | 
| 
       77 
83 
     | 
    
         
             
                                span<>(ng-bind="value || 'null'")
         
     | 
| 
      
 84 
     | 
    
         
            +
                            .path-value.well.well-sm(ng-if="trace.path")
         
     | 
| 
      
 85 
     | 
    
         
            +
                              span Path
         
     | 
| 
      
 86 
     | 
    
         
            +
                              div
         
     | 
| 
      
 87 
     | 
    
         
            +
                                span<>(ng-bind="trace.path")
         
     | 
| 
      
 88 
     | 
    
         
            +
                                span<>(ng-bind="trace.lineno")
         
     | 
| 
       78 
89 
     | 
    
         | 
| 
       79 
90 
     | 
    
         
             
                      .right-info.col-sm-2
         
     | 
| 
       80 
91 
     | 
    
         | 
| 
       81 
     | 
    
         
            -
                script src=" 
     | 
| 
      
 92 
     | 
    
         
            +
                script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular.min.js"
         
     | 
| 
       82 
93 
     | 
    
         | 
| 
       83 
94 
     | 
    
         
             
                javascript:
         
     | 
| 
       84 
95 
     | 
    
         
             
                  sourceRoute = angular.module('SourceRoute', [])
         
     | 
| 
         @@ -97,6 +108,14 @@ html 
     | 
|
| 
       97 
108 
     | 
    
         | 
| 
       98 
109 
     | 
    
         
             
                    $scope.definedClasses = _.uniq(_.map($scope.traces, 'defined_class'))
         
     | 
| 
       99 
110 
     | 
    
         | 
| 
      
 111 
     | 
    
         
            +
                    $scope.callLevelClass = function(trace) {
         
     | 
| 
      
 112 
     | 
    
         
            +
                      if (trace.parent_length > 4) {
         
     | 
| 
      
 113 
     | 
    
         
            +
                        return 'call-level-4'
         
     | 
| 
      
 114 
     | 
    
         
            +
                      } else {
         
     | 
| 
      
 115 
     | 
    
         
            +
                        return 'call-level-' + trace.parent_length
         
     | 
| 
      
 116 
     | 
    
         
            +
                      }
         
     | 
| 
      
 117 
     | 
    
         
            +
                    }
         
     | 
| 
      
 118 
     | 
    
         
            +
             
     | 
| 
       100 
119 
     | 
    
         
             
                    $scope.resetTraceFilter = function() {
         
     | 
| 
       101 
120 
     | 
    
         
             
                      $scope.traceFilter = {}
         
     | 
| 
       102 
121 
     | 
    
         
             
                    }
         
     | 
| 
         @@ -1,9 +1,10 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module SourceRoute
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
              class  
     | 
| 
      
 3 
     | 
    
         
            +
              class GenerateResult
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
                Config = Struct.new(:format, :show_additional_attrs,
         
     | 
| 
       6 
     | 
    
         
            -
                                    :include_local_var, :include_instance_var, 
     | 
| 
      
 6 
     | 
    
         
            +
                                    :include_local_var, :include_instance_var,
         
     | 
| 
      
 7 
     | 
    
         
            +
                                    :filename, :import_return_to_call) do
         
     | 
| 
       7 
8 
     | 
    
         
             
                  def initialize(f="silence", s=[], ilr=false, iiv=false)
         
     | 
| 
       8 
9 
     | 
    
         
             
                    super(f, s, ilr, iiv)
         
     | 
| 
       9 
10 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -121,6 +122,6 @@ module SourceRoute 
     | 
|
| 
       121 
122 
     | 
    
         
             
                  ap "#{@collect_data[:defined_class].inspect}##{@collect_data[:method_id]}"
         
     | 
| 
       122 
123 
     | 
    
         
             
                end
         
     | 
| 
       123 
124 
     | 
    
         | 
| 
       124 
     | 
    
         
            -
              end # END  
     | 
| 
      
 125 
     | 
    
         
            +
              end # END GenerateResult
         
     | 
| 
       125 
126 
     | 
    
         | 
| 
       126 
127 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,61 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module SourceRoute
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
              class TpResultChain
         
     | 
| 
      
 4 
     | 
    
         
            +
                extend Forwardable
         
     | 
| 
      
 5 
     | 
    
         
            +
                def_delegators :@chain, :each, :index, :first, :last, :size, :push, :values_at, :pop
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                include Enumerable
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                def initialize
         
     | 
| 
      
 10 
     | 
    
         
            +
                  @chain = []
         
     | 
| 
      
 11 
     | 
    
         
            +
                end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                def call_chain
         
     | 
| 
      
 14 
     | 
    
         
            +
                  select { |tpr| tpr[:event] == :call }
         
     | 
| 
      
 15 
     | 
    
         
            +
                end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                def return_chain
         
     | 
| 
      
 18 
     | 
    
         
            +
                  select { |tpr| tpr[:event] == :return }
         
     | 
| 
      
 19 
     | 
    
         
            +
                end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                def import_return_value_to_call_chain
         
     | 
| 
      
 22 
     | 
    
         
            +
                  call_chain.each do |ctp|
         
     | 
| 
      
 23 
     | 
    
         
            +
                    ctp[:return_value] = return_chain.detect do |rtp|
         
     | 
| 
      
 24 
     | 
    
         
            +
                      rtp[:defined_class] == ctp[:defined_class] and rtp[:method_id] == ctp[:method_id]
         
     | 
| 
      
 25 
     | 
    
         
            +
                    end[:return_value]
         
     | 
| 
      
 26 
     | 
    
         
            +
                  end
         
     | 
| 
      
 27 
     | 
    
         
            +
                end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                def order_call_chain
         
     | 
| 
      
 30 
     | 
    
         
            +
                  init_order_id_and_parent_ids
         
     | 
| 
      
 31 
     | 
    
         
            +
                  call_chain.each do |tpr|
         
     | 
| 
      
 32 
     | 
    
         
            +
                    return_tpr = return_chain.find do |rtpr|
         
     | 
| 
      
 33 
     | 
    
         
            +
                      rtpr[:defined_class] == tpr[:defined_class] and rtpr[:method_id] == tpr[:method_id]
         
     | 
| 
      
 34 
     | 
    
         
            +
                    end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                    start_index, end_index = tpr[:order_id], return_tpr[:order_id]
         
     | 
| 
      
 37 
     | 
    
         
            +
                    unless end_index == start_index + 1
         
     | 
| 
      
 38 
     | 
    
         
            +
                      values_at(start_index+1 ... end_index).select { |tpr| tpr[:event] == :call }.each do |tpr|
         
     | 
| 
      
 39 
     | 
    
         
            +
                        tpr[:parent_ids].push start_index
         
     | 
| 
      
 40 
     | 
    
         
            +
                      end
         
     | 
| 
      
 41 
     | 
    
         
            +
                    end
         
     | 
| 
      
 42 
     | 
    
         
            +
                  end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                  cal_parent_length
         
     | 
| 
      
 45 
     | 
    
         
            +
                end
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                private
         
     | 
| 
      
 48 
     | 
    
         
            +
                def init_order_id_and_parent_ids
         
     | 
| 
      
 49 
     | 
    
         
            +
                  each_with_index do |tpr, index|
         
     | 
| 
      
 50 
     | 
    
         
            +
                    tpr[:order_id], tpr[:parent_ids] = index, [-1]
         
     | 
| 
      
 51 
     | 
    
         
            +
                  end
         
     | 
| 
      
 52 
     | 
    
         
            +
                end
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                def cal_parent_length
         
     | 
| 
      
 55 
     | 
    
         
            +
                  each do |tpr|
         
     | 
| 
      
 56 
     | 
    
         
            +
                    tpr[:parent_length] = tpr[:parent_ids].length
         
     | 
| 
      
 57 
     | 
    
         
            +
                  end
         
     | 
| 
      
 58 
     | 
    
         
            +
                end
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
              end # END TpResultChain
         
     | 
| 
      
 61 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/source_route/version.rb
    CHANGED
    
    
    
        data/lib/source_route/wrapper.rb
    CHANGED
    
    | 
         @@ -5,10 +5,14 @@ module SourceRoute 
     | 
|
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
                TRACE_POINT_METHODS = [:defined_class, :method_id, :path, :lineno]
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
                attr_accessor :condition, :tp 
     | 
| 
      
 8 
     | 
    
         
            +
                attr_accessor :condition, :tp
         
     | 
| 
      
 9 
     | 
    
         
            +
                attr_reader :tp_result_chain
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                extend Forwardable
         
     | 
| 
      
 12 
     | 
    
         
            +
                def_delegators :@tp_result_chain, :import_return_value_to_call_chain, :order_call_chain, :call_chain, :return_chain
         
     | 
| 
       9 
13 
     | 
    
         | 
| 
       10 
14 
     | 
    
         
             
                Condition = Struct.new(:events, :negatives, :positive, :result_config) do
         
     | 
| 
       11 
     | 
    
         
            -
                  def initialize(e=[:call], n={}, p={}, r= 
     | 
| 
      
 15 
     | 
    
         
            +
                  def initialize(e=[:call], n={}, p={}, r=GenerateResult::Config.new)
         
     | 
| 
       12 
16 
     | 
    
         
             
                    super(e, n, p, r)
         
     | 
| 
       13 
17 
     | 
    
         
             
                  end
         
     | 
| 
       14 
18 
     | 
    
         
             
                end
         
     | 
| 
         @@ -46,13 +50,13 @@ module SourceRoute 
     | 
|
| 
       46 
50 
     | 
    
         
             
                def reset
         
     | 
| 
       47 
51 
     | 
    
         
             
                  @tp.disable if @tp
         
     | 
| 
       48 
52 
     | 
    
         
             
                  @condition = Condition.new
         
     | 
| 
       49 
     | 
    
         
            -
                  @ 
     | 
| 
      
 53 
     | 
    
         
            +
                  @tp_result_chain = TpResultChain.new
         
     | 
| 
       50 
54 
     | 
    
         
             
                  self
         
     | 
| 
       51 
55 
     | 
    
         
             
                end
         
     | 
| 
       52 
56 
     | 
    
         | 
| 
       53 
57 
     | 
    
         
             
                def trace
         
     | 
| 
       54 
58 
     | 
    
         
             
                  # dont wanna init it in tp block, cause tp block could run thousands of times in one cycle trace
         
     | 
| 
       55 
     | 
    
         
            -
                  tp_result =  
     | 
| 
      
 59 
     | 
    
         
            +
                  tp_result = GenerateResult.new(self)
         
     | 
| 
       56 
60 
     | 
    
         
             
                  tp_filter = TpFilter.new(condition)
         
     | 
| 
       57 
61 
     | 
    
         | 
| 
       58 
62 
     | 
    
         
             
                  track = TracePoint.new *condition.events do |tp|
         
     | 
| 
         @@ -61,7 +65,7 @@ module SourceRoute 
     | 
|
| 
       61 
65 
     | 
    
         | 
| 
       62 
66 
     | 
    
         
             
                    unless condition.result_config.format.is_a? Proc
         
     | 
| 
       63 
67 
     | 
    
         
             
                      ret_data = tp_result.build(tp)
         
     | 
| 
       64 
     | 
    
         
            -
                       
     | 
| 
      
 68 
     | 
    
         
            +
                      @tp_result_chain.push(ret_data)
         
     | 
| 
       65 
69 
     | 
    
         
             
                    end
         
     | 
| 
       66 
70 
     | 
    
         | 
| 
       67 
71 
     | 
    
         
             
                    tp_result.output(tp)
         
     | 
| 
         @@ -71,21 +75,6 @@ module SourceRoute 
     | 
|
| 
       71 
75 
     | 
    
         
             
                  track
         
     | 
| 
       72 
76 
     | 
    
         
             
                end
         
     | 
| 
       73 
77 
     | 
    
         | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
                  call_tp_results.each do |ctp|
         
     | 
| 
       76 
     | 
    
         
            -
                    ctp[:return_value] = return_tp_results.detect do |rtp|
         
     | 
| 
       77 
     | 
    
         
            -
                      rtp[:defined_class] == ctp[:defined_class] and rtp[:method_id] == ctp[:method_id]
         
     | 
| 
       78 
     | 
    
         
            -
                    end[:return_value]
         
     | 
| 
       79 
     | 
    
         
            -
                  end
         
     | 
| 
       80 
     | 
    
         
            -
                end
         
     | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
       82 
     | 
    
         
            -
                def call_tp_results
         
     | 
| 
       83 
     | 
    
         
            -
                  tp_attrs_results.select { |tpr| tpr[:event] == :call }
         
     | 
| 
       84 
     | 
    
         
            -
                end
         
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
       86 
     | 
    
         
            -
                def return_tp_results
         
     | 
| 
       87 
     | 
    
         
            -
                  tp_attrs_results.select { |tpr| tpr[:event] == :return }
         
     | 
| 
       88 
     | 
    
         
            -
                end
         
     | 
| 
       89 
     | 
    
         
            -
              end # Wrapper
         
     | 
| 
      
 78 
     | 
    
         
            +
              end # END Wrapper
         
     | 
| 
       90 
79 
     | 
    
         | 
| 
       91 
80 
     | 
    
         
             
            end
         
     | 
    
        data/test/source_route_test.rb
    CHANGED
    
    | 
         @@ -35,14 +35,14 @@ class SourceRouteTest < Minitest::Test 
     | 
|
| 
       35 
35 
     | 
    
         
             
                end
         
     | 
| 
       36 
36 
     | 
    
         
             
                SampleApp.new.nonsense
         
     | 
| 
       37 
37 
     | 
    
         | 
| 
       38 
     | 
    
         
            -
                assert_includes @wrapper. 
     | 
| 
      
 38 
     | 
    
         
            +
                assert_includes @wrapper.tp_result_chain.first[:path], 'test'
         
     | 
| 
       39 
39 
     | 
    
         
             
              end
         
     | 
| 
       40 
40 
     | 
    
         | 
| 
       41 
41 
     | 
    
         
             
              def test_match_class_name_by_first_parameter
         
     | 
| 
       42 
42 
     | 
    
         
             
                @source_route = SourceRoute.enable 'SampleApp'
         
     | 
| 
       43 
43 
     | 
    
         
             
                SampleApp.new.nonsense
         
     | 
| 
       44 
44 
     | 
    
         | 
| 
       45 
     | 
    
         
            -
                assert @wrapper. 
     | 
| 
      
 45 
     | 
    
         
            +
                assert @wrapper.tp_result_chain.size > 0
         
     | 
| 
       46 
46 
     | 
    
         
             
              end
         
     | 
| 
       47 
47 
     | 
    
         | 
| 
       48 
48 
     | 
    
         
             
              def test_match_class_name
         
     | 
| 
         @@ -51,26 +51,26 @@ class SourceRouteTest < Minitest::Test 
     | 
|
| 
       51 
51 
     | 
    
         
             
                end
         
     | 
| 
       52 
52 
     | 
    
         | 
| 
       53 
53 
     | 
    
         
             
                SampleApp.new.nonsense
         
     | 
| 
       54 
     | 
    
         
            -
                assert @wrapper. 
     | 
| 
      
 54 
     | 
    
         
            +
                assert @wrapper.tp_result_chain.size > 0
         
     | 
| 
       55 
55 
     | 
    
         
             
              end
         
     | 
| 
       56 
56 
     | 
    
         | 
| 
       57 
57 
     | 
    
         
             
              def test_source_route_with_one_parameter
         
     | 
| 
       58 
58 
     | 
    
         
             
                @source_route = SourceRoute.enable 'nonsense'
         
     | 
| 
       59 
59 
     | 
    
         
             
                SampleApp.new.nonsense
         
     | 
| 
       60 
60 
     | 
    
         | 
| 
       61 
     | 
    
         
            -
                ret_value = @wrapper. 
     | 
| 
      
 61 
     | 
    
         
            +
                ret_value = @wrapper.tp_result_chain.last
         
     | 
| 
       62 
62 
     | 
    
         
             
                assert_equal SampleApp, ret_value[:defined_class]
         
     | 
| 
       63 
63 
     | 
    
         
             
              end
         
     | 
| 
       64 
64 
     | 
    
         | 
| 
       65 
65 
     | 
    
         
             
              def test_wrapper_reset
         
     | 
| 
       66 
66 
     | 
    
         
             
                SourceRoute.enable 'nonsense'
         
     | 
| 
       67 
67 
     | 
    
         
             
                SampleApp.new.nonsense
         
     | 
| 
       68 
     | 
    
         
            -
                assert_equal 1, @wrapper. 
     | 
| 
      
 68 
     | 
    
         
            +
                assert_equal 1, @wrapper.tp_result_chain.size
         
     | 
| 
       69 
69 
     | 
    
         | 
| 
       70 
70 
     | 
    
         
             
                SourceRoute.reset
         
     | 
| 
       71 
71 
     | 
    
         
             
                SampleApp.new.nonsense
         
     | 
| 
       72 
72 
     | 
    
         | 
| 
       73 
     | 
    
         
            -
                assert_equal 0, @wrapper. 
     | 
| 
      
 73 
     | 
    
         
            +
                assert_equal 0, @wrapper.tp_result_chain.size
         
     | 
| 
       74 
74 
     | 
    
         
             
              end
         
     | 
| 
       75 
75 
     | 
    
         | 
| 
       76 
76 
     | 
    
         
             
              def test_source_route_with_block_only
         
     | 
| 
         @@ -83,7 +83,7 @@ class SourceRouteTest < Minitest::Test 
     | 
|
| 
       83 
83 
     | 
    
         
             
                end
         
     | 
| 
       84 
84 
     | 
    
         
             
                SampleApp.new.nonsense
         
     | 
| 
       85 
85 
     | 
    
         | 
| 
       86 
     | 
    
         
            -
                assert_equal 0, @wrapper. 
     | 
| 
      
 86 
     | 
    
         
            +
                assert_equal 0, @wrapper.tp_result_chain.size
         
     | 
| 
       87 
87 
     | 
    
         
             
                assert_equal 1, paths.size
         
     | 
| 
       88 
88 
     | 
    
         
             
                assert_includes paths.first, 'sample_app'
         
     | 
| 
       89 
89 
     | 
    
         
             
              end
         
     | 
| 
         @@ -93,14 +93,14 @@ class SourceRouteTest < Minitest::Test 
     | 
|
| 
       93 
93 
     | 
    
         
             
                  'abc'.upcase
         
     | 
| 
       94 
94 
     | 
    
         
             
                end
         
     | 
| 
       95 
95 
     | 
    
         | 
| 
       96 
     | 
    
         
            -
                assert_equal 2, @wrapper. 
     | 
| 
      
 96 
     | 
    
         
            +
                assert_equal 2, @wrapper.tp_result_chain.size
         
     | 
| 
       97 
97 
     | 
    
         
             
              end
         
     | 
| 
       98 
98 
     | 
    
         | 
| 
       99 
99 
     | 
    
         
             
              def test_trace_without_first_hash_option
         
     | 
| 
       100 
100 
     | 
    
         
             
                SourceRoute.trace output_format: :test do
         
     | 
| 
       101 
101 
     | 
    
         
             
                  SampleApp.new.nonsense
         
     | 
| 
       102 
102 
     | 
    
         
             
                end
         
     | 
| 
       103 
     | 
    
         
            -
                assert @wrapper. 
     | 
| 
      
 103 
     | 
    
         
            +
                assert @wrapper.tp_result_chain.size > 0
         
     | 
| 
       104 
104 
     | 
    
         
             
                refute @wrapper.tp.enabled?
         
     | 
| 
       105 
105 
     | 
    
         
             
              end
         
     | 
| 
       106 
106 
     | 
    
         | 
| 
         @@ -109,7 +109,7 @@ class SourceRouteTest < Minitest::Test 
     | 
|
| 
       109 
109 
     | 
    
         
             
                  event :call, :return
         
     | 
| 
       110 
110 
     | 
    
         
             
                end
         
     | 
| 
       111 
111 
     | 
    
         
             
                SampleApp.new.nonsense
         
     | 
| 
       112 
     | 
    
         
            -
                assert_equal 2, @wrapper. 
     | 
| 
      
 112 
     | 
    
         
            +
                assert_equal 2, @wrapper.tp_result_chain.size
         
     | 
| 
       113 
113 
     | 
    
         
             
              end
         
     | 
| 
       114 
114 
     | 
    
         | 
| 
       115 
115 
     | 
    
         
             
              def test_show_local_variables
         
     | 
| 
         @@ -119,9 +119,9 @@ class SourceRouteTest < Minitest::Test 
     | 
|
| 
       119 
119 
     | 
    
         
             
                end
         
     | 
| 
       120 
120 
     | 
    
         | 
| 
       121 
121 
     | 
    
         
             
                SampleApp.new.nonsense_with_params(88)
         
     | 
| 
       122 
     | 
    
         
            -
                assert_equal 1, @wrapper. 
     | 
| 
      
 122 
     | 
    
         
            +
                assert_equal 1, @wrapper.tp_result_chain.size
         
     | 
| 
       123 
123 
     | 
    
         | 
| 
       124 
     | 
    
         
            -
                ret_value = @wrapper. 
     | 
| 
      
 124 
     | 
    
         
            +
                ret_value = @wrapper.tp_result_chain.last
         
     | 
| 
       125 
125 
     | 
    
         | 
| 
       126 
126 
     | 
    
         
             
                assert_equal 88, ret_value[:local_var][:param1]
         
     | 
| 
       127 
127 
     | 
    
         
             
                assert_equal nil, ret_value[:local_var][:param2]
         
     | 
| 
         @@ -134,9 +134,9 @@ class SourceRouteTest < Minitest::Test 
     | 
|
| 
       134 
134 
     | 
    
         
             
                end
         
     | 
| 
       135 
135 
     | 
    
         | 
| 
       136 
136 
     | 
    
         
             
                SampleApp.new.nonsense_with_params(88)
         
     | 
| 
       137 
     | 
    
         
            -
                assert_equal 1, @wrapper. 
     | 
| 
      
 137 
     | 
    
         
            +
                assert_equal 1, @wrapper.tp_result_chain.size
         
     | 
| 
       138 
138 
     | 
    
         | 
| 
       139 
     | 
    
         
            -
                ret_value_for_return_event = @wrapper. 
     | 
| 
      
 139 
     | 
    
         
            +
                ret_value_for_return_event = @wrapper.tp_result_chain.last
         
     | 
| 
       140 
140 
     | 
    
         
             
                assert_equal 88, ret_value_for_return_event[:local_var][:param1]
         
     | 
| 
       141 
141 
     | 
    
         
             
                assert_equal 5, ret_value_for_return_event[:local_var][:param2]
         
     | 
| 
       142 
142 
     | 
    
         
             
              end
         
     | 
| 
         @@ -148,22 +148,38 @@ class SourceRouteTest < Minitest::Test 
     | 
|
| 
       148 
148 
     | 
    
         | 
| 
       149 
149 
     | 
    
         
             
                SampleApp.new('ins sure').nonsense_with_instance_var
         
     | 
| 
       150 
150 
     | 
    
         | 
| 
       151 
     | 
    
         
            -
                assert_equal 2, @wrapper. 
     | 
| 
       152 
     | 
    
         
            -
                ret_value = @wrapper. 
     | 
| 
      
 151 
     | 
    
         
            +
                assert_equal 2, @wrapper.tp_result_chain.size
         
     | 
| 
      
 152 
     | 
    
         
            +
                ret_value = @wrapper.tp_result_chain.pop
         
     | 
| 
       153 
153 
     | 
    
         | 
| 
       154 
154 
     | 
    
         
             
                assert_equal 'ins sure', ret_value[:instance_var][:@sample]
         
     | 
| 
       155 
155 
     | 
    
         
             
              end
         
     | 
| 
       156 
156 
     | 
    
         | 
| 
       157 
157 
     | 
    
         
             
              def test_import_return_to_call
         
     | 
| 
       158 
     | 
    
         
            -
                 
     | 
| 
      
 158 
     | 
    
         
            +
                SourceRoute.enable 'SampleApp' do
         
     | 
| 
       159 
159 
     | 
    
         
             
                  event :call, :return
         
     | 
| 
       160 
160 
     | 
    
         
             
                  result_config.include_instance_var = true
         
     | 
| 
       161 
161 
     | 
    
         
             
                  result_config.include_local_var = true
         
     | 
| 
       162 
162 
     | 
    
         
             
                  result_config.import_return_to_call = true
         
     | 
| 
       163 
163 
     | 
    
         
             
                end
         
     | 
| 
       164 
164 
     | 
    
         
             
                SampleApp.new.init_cool_app
         
     | 
| 
       165 
     | 
    
         
            -
                @wrapper. 
     | 
| 
       166 
     | 
    
         
            -
                assert @wrapper. 
     | 
| 
      
 165 
     | 
    
         
            +
                @wrapper.import_return_value_to_call_chain
         
     | 
| 
      
 166 
     | 
    
         
            +
                assert @wrapper.call_chain[0].key?(:return_value), 'call results should contain return_value'
         
     | 
| 
      
 167 
     | 
    
         
            +
              end
         
     | 
| 
      
 168 
     | 
    
         
            +
             
     | 
| 
      
 169 
     | 
    
         
            +
              def test_order_call_sequence
         
     | 
| 
      
 170 
     | 
    
         
            +
                SourceRoute.enable 'SampleApp' do
         
     | 
| 
      
 171 
     | 
    
         
            +
                  event :call, :return
         
     | 
| 
      
 172 
     | 
    
         
            +
                end
         
     | 
| 
      
 173 
     | 
    
         
            +
                SampleApp.new.nonsense_with_instance_var
         
     | 
| 
      
 174 
     | 
    
         
            +
                @wrapper.order_call_chain
         
     | 
| 
      
 175 
     | 
    
         
            +
                @wrapper.order_call_chain
         
     | 
| 
      
 176 
     | 
    
         
            +
                call_results = @wrapper.call_chain
         
     | 
| 
      
 177 
     | 
    
         
            +
             
     | 
| 
      
 178 
     | 
    
         
            +
                nonsense_call_tp = call_results.find { |tp| tp[:method_id] == :nonsense }
         
     | 
| 
      
 179 
     | 
    
         
            +
                nonsense_with_instance_var_call_tp = call_results.find { |tp| tp[:method_id] == :nonsense_with_instance_var }
         
     | 
| 
      
 180 
     | 
    
         
            +
             
     | 
| 
      
 181 
     | 
    
         
            +
                assert_equal [-1, nonsense_with_instance_var_call_tp[:order_id]], nonsense_call_tp[:parent_ids]
         
     | 
| 
      
 182 
     | 
    
         
            +
                assert_equal 2, nonsense_call_tp[:parent_length]
         
     | 
| 
       167 
183 
     | 
    
         
             
              end
         
     | 
| 
       168 
184 
     | 
    
         | 
| 
       169 
185 
     | 
    
         
             
              # Nothing has tested really when run rake cause ENV['ignore_html_generation'] was set to true
         
     | 
    
        data/test/tp_filter_test.rb
    CHANGED
    
    | 
         @@ -14,7 +14,7 @@ module SourceRoute 
     | 
|
| 
       14 
14 
     | 
    
         
             
                  @warden_tp = FakeTp.new(:auth, Warden, 6)
         
     | 
| 
       15 
15 
     | 
    
         
             
                  @user_tp = FakeTp.new(:new, User, 8)
         
     | 
| 
       16 
16 
     | 
    
         
             
                  @tps = [@devise_tp, @warden_tp, @user_tp]
         
     | 
| 
       17 
     | 
    
         
            -
                  @result_config =  
     | 
| 
      
 17 
     | 
    
         
            +
                  @result_config = GenerateResult::Config.new('silence', [], false, false)
         
     | 
| 
       18 
18 
     | 
    
         
             
                end
         
     | 
| 
       19 
19 
     | 
    
         | 
| 
       20 
20 
     | 
    
         
             
                def test_filter_method_not_auth
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: source_route
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.0 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - raykin
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2014-10- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2014-10-25 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: awesome_print
         
     | 
| 
         @@ -121,13 +121,15 @@ files: 
     | 
|
| 
       121 
121 
     | 
    
         
             
            - LICENSE.txt
         
     | 
| 
       122 
122 
     | 
    
         
             
            - README.md
         
     | 
| 
       123 
123 
     | 
    
         
             
            - Rakefile
         
     | 
| 
      
 124 
     | 
    
         
            +
            - examples/callback_in_activesupport.rb
         
     | 
| 
       124 
125 
     | 
    
         
             
            - examples/show_init_files_when_rails_server_start.rb
         
     | 
| 
       125 
126 
     | 
    
         
             
            - examples/show_task_trace_in_rails.rb
         
     | 
| 
       126 
127 
     | 
    
         
             
            - lib/source_route.rb
         
     | 
| 
       127 
128 
     | 
    
         
             
            - lib/source_route/formats/html.rb
         
     | 
| 
       128 
129 
     | 
    
         
             
            - lib/source_route/formats/html_template.slim
         
     | 
| 
      
 130 
     | 
    
         
            +
            - lib/source_route/generate_result.rb
         
     | 
| 
       129 
131 
     | 
    
         
             
            - lib/source_route/tp_filter.rb
         
     | 
| 
       130 
     | 
    
         
            -
            - lib/source_route/ 
     | 
| 
      
 132 
     | 
    
         
            +
            - lib/source_route/tp_result_chain.rb
         
     | 
| 
       131 
133 
     | 
    
         
             
            - lib/source_route/version.rb
         
     | 
| 
       132 
134 
     | 
    
         
             
            - lib/source_route/wrapper.rb
         
     | 
| 
       133 
135 
     | 
    
         
             
            - source_route.gemspec
         
     |