source_route 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 89e5066f6c1b4590957260ef57b44982b01cf006
4
- data.tar.gz: 3ae996d75fa35ba29b45e1afe7a77ae3932984d8
3
+ metadata.gz: fd182d935ed8eb7520d0cebb22fe7af916d0d137
4
+ data.tar.gz: 44b50d2846f827b6a15cd98a0a49125c34f965da
5
5
  SHA512:
6
- metadata.gz: 332fe83850831d9c872bdbfdf05a3d1fc3eb047704a7308a18ad93f6308beba1332b63164261917fe51468e7a128f1769a509e5061c218868723a0990a78728c
7
- data.tar.gz: aa108ff2d48aee83a49c45d5d2a65152512a7a94a7fd33f7614939cd771a0f97949efe9d09761e2cf6d12c5cac6578aab3680497a67f5a621761547fdd5e05e4
6
+ metadata.gz: 4bf100bdc4ff65df991267c0905d9f8546f6a70e7b8860262d0b275c918a73bb17dd953cc6da896280e92a2f24702eb7c4e8edaed551d044acf603b535410fd4
7
+ data.tar.gz: 6b5a8dc7cf522fbdcd7520c10377d9d5bac16d069e1d6df52ba82b4290c5b82438a42bc1a11042fda38a3ec76e2a007c19fcfc67c9e1b61ed09f29624ddebe0a
data/README.md CHANGED
@@ -64,7 +64,7 @@ Same as the previous example, you will get a html file showing the code trace.
64
64
  It will output the trace when you run the application.
65
65
 
66
66
  see more usage in examples.
67
- see full usage in examples/callback_in_activesupport.rb
67
+ see full usage in examples/study_callback.rb
68
68
 
69
69
  ## Why
70
70
 
@@ -97,10 +97,13 @@ Finally, I expect my working style can change from searching workaround from int
97
97
 
98
98
  Dynamic indent when new child level comes.
99
99
 
100
+ Is it possible to easily open only direct child
100
101
  Animation when child was click.
101
102
 
102
103
  Show loading when click clear. (when $apply() take more than 1 seconds to run)
103
104
 
104
105
  Add debug option to provide more verbose messages of what has happened
105
106
 
106
- Open File directly from browser(chrome) by plugin?
107
+ if instance val contains symbol as value, the json output will be string. It could be confused others.
108
+
109
+ Open File directly from browser(chrome) by plugin? Maybe check out how better error implement this
@@ -0,0 +1,35 @@
1
+ require 'active_support/callbacks'
2
+
3
+ require 'source_route'
4
+
5
+ SourceRoute.enable do
6
+ method_id 'base_decorate', 'prepare_decorate'
7
+ defined_class 'ActiveSupport::Callbacks', 'PersonRecord', 'Filters'
8
+ result_config.filename = 'trace_callback.html'
9
+ full_feature 10
10
+ end
11
+
12
+ class House
13
+ include ActiveSupport::Callbacks
14
+ define_callbacks :decorate
15
+
16
+ def base_decorate
17
+ run_callbacks :decorate do
18
+ puts "Let's decorate house"
19
+ end
20
+ end
21
+ end
22
+
23
+ class KattyHouse < House
24
+ set_callback :decorate, :after, :prepare_decorate
25
+
26
+ def prepare_decorate
27
+ puts "Preparing: buy materials ......"
28
+ end
29
+ end
30
+
31
+ katty_house = KattyHouse.new
32
+
33
+ katty_house.base_decorate
34
+
35
+ SourceRoute.output_html
@@ -43,7 +43,7 @@ html
43
43
  button.btn.btn-default>(ng-click="outlineTrace()")
44
44
  span> OutLine
45
45
  span
46
- button.btn.btn-primary(ng-click="removeOutlineTrace()") Clear
46
+ button.btn.btn-primary(ng-click="removeOutlineTrace()") Expand ALL
47
47
 
48
48
  .trace-flow
49
49
  .row
@@ -64,7 +64,7 @@ html
64
64
  i.fa.fa-angle-right
65
65
  span Child
66
66
  button.btn.btn-info.btn-sm(ng-show="::containsDetail(trace)" ng-click="showMoreDetail = !showMoreDetail") Details
67
- span(ng-bind="trace.defined_class")
67
+ span(ng-bind="::tpSelfList[trace.tp_self]")
68
68
  span
69
69
  | .
70
70
  mark.method-value(ng-bind="trace.method_id")
@@ -72,9 +72,9 @@ html
72
72
  div(ng-if="trace.hasOwnProperty('return_value')")
73
73
  span
74
74
  | =>
75
- span<(ng-bind="trace.return_value.substring(0, 200) | json")
75
+ span<(ng-bind="::trimString(trace.return_value, 200)")
76
76
 
77
- .details(ng-if="showMoreDetail")
77
+ .details(ng-if="showMoreDetail" style="margin-top: 10px")
78
78
  .attrs.well.well-sm(ng-if="containsOtherAttrs(trace)")
79
79
  span Attrs
80
80
  div(hljs source="::combinedAttrs(trace) | json")
@@ -84,6 +84,9 @@ html
84
84
  .ins-vars.well.well-sm(ng-if="trace.instance_var")
85
85
  span Instance Var
86
86
  .ins-values(hljs source="::trace.instance_var | json")
87
+ .return-value(ng-if="trace.hasOwnProperty('return_value')")
88
+ span Return Value
89
+ .value(hljs source="::trace.return_value | json")
87
90
 
88
91
  .right-info.col-sm-2
89
92
 
@@ -94,31 +97,40 @@ html
94
97
  javascript:
95
98
  sourceRoute = angular.module('SourceRoute', ['ui.bootstrap', 'hljs'])
96
99
  sourceRoute.controller('MainCtrl', function($scope, $filter) {
100
+
101
+ $scope.trimString = function(str, length) {
102
+ return str.length > length ? str.substring(0, length - 3) + '...' : str;
103
+ }
104
+
97
105
  $scope.traces = angular.element("#trace-data").data('trace')
98
106
  $scope.tpSelfList = angular.element("#trace-data").data('tp-self-caches')
99
107
  $scope.tpEvents = angular.element("#trace-data").data('tp-events')
100
- $scope.childParentFilter = { hide_parent_ids: [] }
108
+ $scope.childParentFilter = { hide_trace_ids: [] }
101
109
 
102
110
  $scope.childParentFilterFn = function(trace) {
103
- if ($scope.childParentFilter.hide_parent_ids.length == 0) {
111
+ if (!trace.hasOwnProperty('parent_ids')) {
112
+ return true;
113
+ }
114
+ if (trace.parent_ids.length == 0) {
104
115
  return true;
105
116
  } else {
106
- var shared_parents = _.intersection(trace.parent_ids, $scope.childParentFilter.hide_parent_ids);
107
- if (shared_parents.length == 0) {
108
- return true;
117
+ var shared_hide_parents = _.intersection(trace.parent_ids, $scope.childParentFilter.hide_trace_ids);
118
+ if (shared_hide_parents.length > 0 ) {
119
+ return false;
109
120
  }
110
121
  }
122
+ return true;
111
123
  }
112
124
 
113
125
  $scope.removeOutlineTrace = function() {
114
126
  _.each($scope.traces, function(trace) { trace.childClosed = false; });
115
- $scope.childParentFilter.hide_parent_ids = [];
127
+ $scope.childParentFilter.hide_trace_ids = [];
116
128
  }
117
129
 
118
130
  $scope.outlineTrace = function() {
119
- $scope.childParentFilter.hide_parent_ids = [];
131
+ $scope.childParentFilter.hide_trace_ids = [];
120
132
  _.chain($scope.traces).filter({parent_length: 0})
121
- .each(function(trace) { trace.childClosed = true; $scope.childParentFilter.hide_parent_ids.push(trace.order_id) })
133
+ .each(function(trace) { trace.childClosed = true; $scope.childParentFilter.hide_trace_ids.push(trace.order_id) })
122
134
  }
123
135
 
124
136
  $scope.traceFilter = {event: $scope.tpEvents[0]}
@@ -148,7 +160,7 @@ html
148
160
 
149
161
  $scope.containsOtherAttrs = function(trace) {
150
162
  return trace.hasOwnProperty('path') || trace.hasOwnProperty('lineno') ||
151
- trace.hasOwnProperty('tp_self');
163
+ trace.hasOwnProperty('defined_class');
152
164
  }
153
165
 
154
166
  $scope.containsDetail = function(trace) {
@@ -159,16 +171,17 @@ html
159
171
  $scope.combinedAttrs = function(trace) {
160
172
  var attrs = {}
161
173
  if (trace.hasOwnProperty('lineno') && trace.hasOwnProperty('path')) {
162
- attrs.path = trace.path + ":" + trace.lineno;
174
+ attrs.method_defined_on = trace.path + ":" + trace.lineno;
163
175
  } else if (trace.hasOwnProperty('path')) {
164
- attrs.path = trace.path;
176
+ attrs.method_defined_on = trace.path;
165
177
  }
166
- if (trace.hasOwnProperty('tp_self')) {
167
- attrs.self = $scope.tpSelfList[trace.tp_self];
178
+ if (trace.hasOwnProperty('defined_class')) {
179
+ attrs.method_defined_in = trace.defined_class;
168
180
  }
169
181
  return attrs;
170
182
  }
171
183
 
184
+ $scope.outlineTrace();
172
185
  })
173
186
 
174
187
  sourceRoute.controller('TpTraceCtrl', function($scope) {
@@ -182,12 +195,12 @@ html
182
195
 
183
196
  $scope.showChild = function() {
184
197
  $scope.trace.childClosed = false;
185
- _.pull($scope.childParentFilter.hide_parent_ids, $scope.trace.order_id);
198
+ _.pull($scope.childParentFilter.hide_trace_ids, $scope.trace.order_id);
186
199
  }
187
200
 
188
201
  $scope.hideChild = function() {
189
202
  $scope.trace.childClosed = true;
190
- $scope.childParentFilter.hide_parent_ids.push($scope.trace.order_id);
203
+ $scope.childParentFilter.hide_trace_ids.push($scope.trace.order_id);
191
204
  }
192
205
 
193
206
  $scope.hasChild = function() {
@@ -3,7 +3,7 @@ module SourceRoute
3
3
  class GenerateResult
4
4
 
5
5
  Config = Struct.new(:format, :show_additional_attrs,
6
- :include_local_var, :include_instance_var, :include_tp_self,
6
+ :include_local_var, :include_instance_var,
7
7
  :filename, :import_return_to_call) do
8
8
  def initialize(f="silence", s=[], ilr=false, iiv=false)
9
9
  super(f, s, ilr, iiv)
@@ -44,7 +44,7 @@ module SourceRoute
44
44
  def build(trace_point_instance)
45
45
  @tp = trace_point_instance
46
46
  collect_tp_data
47
- collect_tp_self if @config[:include_tp_self]
47
+ collect_tp_self # NEED more check. Does TracePoint support self for all events?
48
48
  collect_local_var_data if @config[:include_local_var]
49
49
  collect_instance_var_data if @config[:include_instance_var]
50
50
  @collect_data
@@ -22,10 +22,13 @@ module SourceRoute
22
22
 
23
23
  def import_return_value_to_call_chain
24
24
  call_chain.each do |ctp|
25
- matched_return_tp = return_chain.detect do |rtp|
25
+ matched_return_tp = return_chain.
26
+ reject { |c| c[:matched] }. # matched return tp should not checked again
27
+ detect do |rtp|
26
28
  rtp[:tp_self] == ctp[:tp_self] and rtp[:method_id] == ctp[:method_id] and rtp[:defined_class] == ctp[:defined_class]
27
29
  end
28
30
  unless matched_return_tp.nil?
31
+ matched_return_tp[:matched] = true
29
32
  ctp[:return_value] = matched_return_tp[:return_value]
30
33
  ctp[:local_var] = matched_return_tp[:local_var] if matched_return_tp.key? :local_var
31
34
  ctp[:instance_var] = matched_return_tp[:instance_var] if matched_return_tp.key? :instance_var
@@ -66,7 +69,7 @@ module SourceRoute
66
69
  # ex: inspect on ActiveRecord_Relation may crash
67
70
  tr[:defined_class] = tr[:defined_class].to_s if tr.key?(:defined_class)
68
71
  if tr.key?(:return_value)
69
- if tr[:return_value].nil? or tr[:return_value] == ''
72
+ if tr[:return_value].nil? or tr[:return_value] == '' or tr[:return_value].is_a? Symbol
70
73
  tr[:return_value] = tr[:return_value].inspect
71
74
  else
72
75
  tr[:return_value] = tr[:return_value].to_s
@@ -1,3 +1,3 @@
1
1
  module SourceRoute
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -46,7 +46,6 @@ module SourceRoute
46
46
 
47
47
  self.events = [:call, :return]
48
48
  result_config.import_return_to_call = true
49
- result_config.include_tp_self = true
50
49
 
51
50
  result_config.show_additional_attrs = [:path, :lineno]
52
51
  # JSON serialize trigger many problems when handle complicated object
@@ -108,18 +108,17 @@ class SourceRouteTest < Minitest::Test
108
108
  SourceRoute.trace method_id: 'nonsense', full_feature: true do
109
109
  SampleApp.new.nonsense
110
110
  end
111
- assert @wrapper.condition.result_config.include_tp_self
112
111
  first_result = @wrapper.tp_result_chain.first
113
112
  assert_equal first_result[:tp_self], 0
114
113
  end
115
114
 
116
- def test_trace_include_tp_self
117
- SourceRoute.trace method_id: 'nonsense', full_feature: true do
118
- SampleApp.new.nonsense
119
- end
120
- assert_equal 1, @wrapper.tp_self_caches.size
121
- assert @wrapper.tp_self_caches.first.is_a? SampleApp
122
- end
115
+ # def test_trace_include_tp_self
116
+ # SourceRoute.trace method_id: 'nonsense', full_feature: true do
117
+ # SampleApp.new.nonsense
118
+ # end
119
+ # assert_equal 1, @wrapper.tp_self_caches.size
120
+ # assert @wrapper.tp_self_caches.first.is_a? SampleApp
121
+ # end
123
122
 
124
123
  def test_stringify_tp_result_chain
125
124
  SourceRoute.trace method_id: 'nonsense', full_feature: true do
@@ -225,7 +224,6 @@ class SourceRouteTest < Minitest::Test
225
224
  result_config.include_instance_var = true
226
225
  result_config.include_local_var = true
227
226
  result_config.show_additional_attrs = [:path, :lineno]
228
- result_config.include_tp_self = true
229
227
 
230
228
  result_config.filename = 'call_and_return_in_sample_app.html'
231
229
  result_config.import_return_to_call = true
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.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - raykin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-13 00:00:00.000000000 Z
11
+ date: 2014-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -121,9 +121,9 @@ files:
121
121
  - LICENSE.txt
122
122
  - README.md
123
123
  - Rakefile
124
- - examples/callback_in_activesupport.rb
125
124
  - examples/show_init_files_when_rails_server_start.rb
126
125
  - examples/show_task_trace_in_rails.rb
126
+ - examples/study_callback.rb
127
127
  - lib/source_route.rb
128
128
  - lib/source_route/formats/html.rb
129
129
  - lib/source_route/formats/html_template.slim
@@ -1,33 +0,0 @@
1
- require 'active_support/callbacks'
2
-
3
- require 'source_route'
4
-
5
- SourceRoute.enable do
6
- defined_class 'ActiveSupport::Callbacks', 'PersonRecord'
7
- method_id :base_save, :saving_message, :callback
8
- full_feature
9
- end
10
-
11
- class Record
12
- include ActiveSupport::Callbacks
13
- define_callbacks :save
14
-
15
- def base_save
16
- run_callbacks :save do
17
- puts "- save"
18
- end
19
- end
20
- end
21
-
22
- class PersonRecord < Record
23
- set_callback :save, :before, :saving_message
24
-
25
- def saving_message
26
- puts "saving..."
27
- end
28
- end
29
-
30
- person = PersonRecord.new
31
- person.base_save
32
-
33
- SourceRoute.build_html_output