source_route 0.0.1 → 0.0.2

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: 8d7a56268a17ce2f0ea56258f3eaa28afac00dac
4
- data.tar.gz: ffd4b43dd9a3b1dfa298695352cec8486c554d21
3
+ metadata.gz: 67d1a63084f0e5b6a0f2e7fb6f066d8b02510590
4
+ data.tar.gz: f7cc2c6ddc3632cde00f74a97b634834df307154
5
5
  SHA512:
6
- metadata.gz: c3a6f2c1acf132f9ef1b8efa0463febbd55e62bc4ecf6f36fc89af0f63793bf662bce96dbfff758663b6753de2e12491284e298da0a25d28f998ca63198320c8
7
- data.tar.gz: 334f6cd5aafc1091a17c67ced52bd9f865a3154894a6ec72806c52eba0caa4a23ad5539df249c0e636f217d012019eebd223d8c6b297a407f892542e2f807b16
6
+ metadata.gz: 001a12df5c3bbb0c3ae80d92f1661732ddbd44689f72cb214b84a3b55e01d266282273e094347ed795816fe3d66fc524247ffa4b3a6a3a5d4cce87f8da70b3b2
7
+ data.tar.gz: 8bd9da28ab7372e981ca605e63402f6bd7637db273be83c920db5b3548a9c6b0af01082b78cf6762a230fda79678be491586ec156168251b5b17195ce6c84a21
data/.gitignore CHANGED
@@ -20,3 +20,4 @@ tmp
20
20
  *.o
21
21
  *.a
22
22
  mkmf.log
23
+ .ruby-version
data/README.md CHANGED
@@ -10,7 +10,7 @@ Wrapper of TracePoint
10
10
 
11
11
  Add this line to your application's Gemfile:
12
12
 
13
- gem 'source_route', git: 'https://github.com/raykin/source-route'
13
+ gem 'source_route'
14
14
 
15
15
  And then execute:
16
16
 
@@ -26,7 +26,7 @@ Or install it yourself as:
26
26
 
27
27
  ## Contributing
28
28
 
29
- 1. Fork it ( https://github.com/[my-github-username]/source_route/fork )
29
+ 1. Fork it ( https://github.com/raykin/source_route/fork )
30
30
  2. Create your feature branch (`git checkout -b my-new-feature`)
31
31
  3. Commit your changes (`git commit -am 'Add some feature'`)
32
32
  4. Push to the branch (`git push origin my-new-feature`)
@@ -11,7 +11,9 @@ html
11
11
  / pry(main)> ActiveRecord::Inheritance::ClassMethods.to_json => {} # Dont know why
12
12
  ruby:
13
13
  trace_data = @tp_attrs_results.map do |tp_result|
14
- tp_result[:defined_class] = tp_result[:defined_class].nature_value
14
+ if tp_result.has_key?(:defined_class)
15
+ tp_result[:defined_class] = tp_result[:defined_class].nature_value
16
+ end
15
17
  tp_result
16
18
  end
17
19
 
@@ -25,16 +27,33 @@ html
25
27
  =< @conditions.event
26
28
  .trace-flow
27
29
  .row
28
- .left-info.col-sm-3
30
+ .left-info.col-sm-4
29
31
  .well.well-sm(ng-repeat="klass in definedClasses")
30
- p.text-center(ng-bind="klass")
31
- .center-info.col-sm-5
32
- .well.well-lg(ng-repeat="trace in traces")
33
- p
32
+ button.btn.btn-default(ng-click="selectKlass(klass)")
33
+ span(ng-bind="klass")
34
+ .center-info.col-sm-6
35
+ .well.well-lg(ng-repeat="trace in traces | filter:{defined_class: selectedKlass}")
36
+ div(ng-click="showMoreDetail = !showMoreDetail")
34
37
  span(ng-bind="trace.defined_class")
35
38
  span #
36
39
  span(ng-bind="trace.method_id")
37
- .right-info.col-sm-3
40
+ .details(ng-if="showMoreDetail")
41
+ .local-vars.well.well-sm(ng-if="trace.local_var" style="color: green")
42
+ span Local Var
43
+ .local-values(ng-repeat="(key, value) in trace.local_var")
44
+ span<>(ng-bind="key")
45
+ span<>
46
+ | =>
47
+ span<>(ng-bind="value || 'null'")
48
+ .ins-vars.well.well-sm(ng-if="trace.instance_var" style="color: blue")
49
+ span Instance Var
50
+ .ins-values(ng-repeat="(key, value) in trace.instance_var")
51
+ span<>(ng-bind="key")
52
+ span<>
53
+ | =>
54
+ span<>(ng-bind="value || 'null'")
55
+
56
+ .right-info.col-sm-2
38
57
 
39
58
  script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular.min.js"
40
59
 
@@ -45,4 +64,13 @@ html
45
64
  // it is possible to prevent dirty check on definedClasses after it was generated
46
65
  $scope.definedClasses = _.uniq(_.map($scope.traces, 'defined_class'))
47
66
  $scope.definedClasses.unshift('ALL')
67
+
68
+ $scope.selectKlass = function(klass) {
69
+ if (klass == 'ALL') {
70
+ $scope.selectedKlass = undefined
71
+ } else {
72
+ $scope.selectedKlass = klass
73
+ }
74
+ }
75
+
48
76
  })
@@ -3,8 +3,8 @@ module SourceRoute
3
3
  class TpResult
4
4
 
5
5
  DEFAULT_ATTRS = {
6
- call: [:defined_class, :event, :method_id],
7
- return: [:defined_class, :event, :method_id, :return_value]
6
+ call: [:defined_class, :method_id],
7
+ return: [:defined_class, :method_id, :return_value]
8
8
  }
9
9
 
10
10
  def initialize(wrapper)
@@ -12,10 +12,13 @@ module SourceRoute
12
12
 
13
13
  @output_config = @wrapper.conditions.result_config
14
14
 
15
- @tp_event = @wrapper.conditions.event.to_sym
16
- if @output_config[:selected_attrs].nil? and [@wrapper.conditions.event].flatten.size == 1
17
- @output_config[:selected_attrs] = DEFAULT_ATTRS[@tp_event] - [:event]
18
- end
15
+ @tp_events = @wrapper.conditions.events
16
+ end
17
+
18
+ def output_attributes(event)
19
+ attrs = @output_config[:selected_attrs] || DEFAULT_ATTRS[event]
20
+ attrs.push(:event) if @tp_events.size > 1
21
+ attrs
19
22
  end
20
23
 
21
24
  def build(trace_point_instance)
@@ -26,7 +29,7 @@ module SourceRoute
26
29
  @collect_data
27
30
  end
28
31
 
29
- # always run build before it # not a good design
32
+ # must run build before it # not a good design
30
33
  def output
31
34
 
32
35
  format = @output_config[:output_format].to_sym
@@ -53,7 +56,7 @@ module SourceRoute
53
56
  private
54
57
 
55
58
  def collect_tp_data
56
- @collect_data = @output_config[:selected_attrs].inject({}) do |memo, key|
59
+ @collect_data = output_attributes(@tp.event).inject({}) do |memo, key|
57
60
  memo[key.to_sym] = @tp.send(key) if @tp.respond_to?(key)
58
61
  memo
59
62
  end
@@ -66,8 +69,9 @@ module SourceRoute
66
69
  @tp.binding.eval('local_variables').each do |v|
67
70
  local_var_hash[v] = @tp.binding.local_variable_get v
68
71
  end
69
-
70
- @collect_data.merge!(local_var: local_var_hash)
72
+ if local_var_hash != {}
73
+ @collect_data.merge!(local_var: local_var_hash)
74
+ end
71
75
  end
72
76
  end
73
77
 
@@ -77,7 +81,9 @@ module SourceRoute
77
81
  @tp.self.instance_variables.each do |key|
78
82
  instance_var_hash[key] = @tp.self.instance_variable_get(key)
79
83
  end
80
- @collect_data.merge!(instance_var: instance_var_hash)
84
+ if instance_var_hash != {}
85
+ @collect_data.merge!(instance_var: instance_var_hash)
86
+ end
81
87
  end
82
88
  end
83
89
 
@@ -1,3 +1,3 @@
1
1
  module SourceRoute
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -13,7 +13,7 @@ module SourceRoute
13
13
  # output_format can be console, html
14
14
  def reset
15
15
  @tp.disable if @tp
16
- @conditions = OpenStruct.new(event: :call, negative: {}, positive: {},
16
+ @conditions = OpenStruct.new(events: :call, negative: {}, positive: {},
17
17
  result_config: { output_format: 'none',
18
18
  selected_attrs: nil,
19
19
  include_local_var: false,
@@ -23,11 +23,10 @@ module SourceRoute
23
23
  self
24
24
  end
25
25
 
26
- # TODO: make event can be array
27
- def event(v)
28
- @conditions.event = v.to_sym unless v.nil?
26
+ def events(v)
27
+ @conditions.events = Array(v).map(&:to_sym) unless v.nil?
29
28
  end
30
-
29
+ alias :event :events
31
30
  def set_result_config(value)
32
31
  unless value.is_a? Hash
33
32
  conditions.result_config = value
@@ -70,7 +69,7 @@ module SourceRoute
70
69
  # dont wanna init it in tp block, cause tp block could run thousands of time in one cycle trace
71
70
  tp_result = TpResult.new(self)
72
71
 
73
- track = TracePoint.new conditions.event do |tp|
72
+ track = TracePoint.new *conditions.events do |tp|
74
73
  negative_break = conditions.negative.any? do |method_key, value|
75
74
  tp.send(method_key).nature_value =~ Regexp.new(value)
76
75
  end
@@ -81,8 +80,8 @@ module SourceRoute
81
80
  next if positive_break
82
81
 
83
82
  ret_data = tp_result.build(tp)
84
- tp_result.output
85
83
  tp_attrs_results.push(ret_data)
84
+ tp_result.output
86
85
  end
87
86
  track.enable
88
87
  self.tp = track
data/lib/source_route.rb CHANGED
@@ -43,7 +43,7 @@ module SourceRoute
43
43
  wrapper.trace
44
44
  yield
45
45
  wrapper.tp.disable
46
- SourceRoute.build_html_output if opt[:output_format] == :html
46
+ SourceRoute.build_html_output if opt[:output_format].to_sym == :html
47
47
  end
48
48
 
49
49
  def build_html_output
data/source_route.gemspec CHANGED
@@ -10,8 +10,9 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["raykincoldxiao@gmail.com"]
11
11
  spec.summary = %q{Wrapper of TracePoint.}
12
12
  spec.description = %q{Wrapper of TracePoint.}
13
- spec.homepage = ""
13
+ spec.homepage = "http://github.com/raykin/source-route"
14
14
  spec.license = "MIT"
15
+ spec.required_ruby_version = '>= 2'
15
16
 
16
17
  spec.files = `git ls-files -z`.split("\x0")
17
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
@@ -23,4 +24,5 @@ Gem::Specification.new do |spec|
23
24
  spec.add_development_dependency "bundler", "~> 1.6"
24
25
  spec.add_development_dependency "rake"
25
26
  spec.add_development_dependency 'slim'
27
+ spec.add_development_dependency 'minitest'
26
28
  end
data/test/sample_app.rb CHANGED
@@ -2,8 +2,8 @@
2
2
  # When add more complex test, update FakeApp
3
3
  class SampleApp
4
4
 
5
- def initialize(cool=nil)
6
- @cool = cool if cool
5
+ def initialize(sample=nil)
6
+ @sample = sample if sample
7
7
  end
8
8
 
9
9
  def nonsense
@@ -17,4 +17,23 @@ class SampleApp
17
17
  def nonsense_with_instance_var
18
18
  nonsense
19
19
  end
20
+
21
+ def init_cool_app
22
+ CoolApp.new.foo
23
+ end
24
+
25
+ class CoolApp
26
+ def initialize
27
+ @cool = ['test', 'data']
28
+ # todo: cant display on html easily
29
+ @cool_hash = {first: :run, second: :halt, third: :stop}
30
+ cool_in_init = 'init data in cool app'
31
+
32
+ end
33
+
34
+ def foo
35
+ cool_in_foo = 'foo data'
36
+ @cool_ins_after = 'will shown in result?'
37
+ end
38
+ end
20
39
  end
data/test/test_helper.rb CHANGED
@@ -5,4 +5,5 @@ require File.join(File.dirname(__FILE__), 'fake_app')
5
5
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
6
 
7
7
  require 'source_route'
8
- require 'byebug'
8
+ # require 'pry'
9
+ # require 'pry-byebug'
data/test/wrapper_test.rb CHANGED
@@ -19,7 +19,7 @@ module SourceRoute
19
19
  assert_equal @wrapper, SourceRoute.wrapper
20
20
  end
21
21
 
22
- def test_catch_call_event_only
22
+ def test_catch_call_event
23
23
  SourceRoute.enable do
24
24
  event :call
25
25
  method_id /nonsense/
@@ -48,7 +48,7 @@ module SourceRoute
48
48
  assert @wrapper.tp_attrs_results.size > 0
49
49
  end
50
50
 
51
- def test_source_route_with_only_one_parameter
51
+ def test_source_route_with_one_parameter
52
52
  @source_route = SourceRoute.enable 'nonsense'
53
53
  SampleApp.new.nonsense
54
54
 
@@ -68,23 +68,31 @@ module SourceRoute
68
68
  end
69
69
 
70
70
  def test_source_route_with_block
71
- SourceRoute.trace method_id: 'nonsense', output_format: :html do
71
+ SourceRoute.trace method_id: 'nonsense', output_format: :test do
72
72
  SampleApp.new.nonsense
73
73
  end
74
74
  assert_equal 1, @wrapper.tp_attrs_results.size
75
75
  refute @wrapper.tp.enabled?
76
76
  end
77
77
 
78
- def test_trace_without_condition
79
- SourceRoute.trace output_format: :html do
78
+ def test_trace_without_first_hash_option
79
+ SourceRoute.trace output_format: :test do
80
80
  SampleApp.new.nonsense
81
81
  end
82
82
  assert @wrapper.tp_attrs_results.size > 0
83
83
  refute @wrapper.tp.enabled?
84
84
  end
85
85
 
86
+ def test_trace_two_events
87
+ SourceRoute.enable 'nonsense' do
88
+ events [:call, :return]
89
+ end
90
+ SampleApp.new.nonsense
91
+ assert_equal 2, @wrapper.tp_attrs_results.size
92
+ end
93
+
86
94
  def test_show_local_variables
87
- @source_route = SourceRoute.enable 'nonsense_with_params' do
95
+ SourceRoute.enable 'nonsense_with_params' do
88
96
  output_include_local_variables
89
97
  end
90
98
 
@@ -94,6 +102,21 @@ module SourceRoute
94
102
  ret_value = @wrapper.tp_attrs_results.last
95
103
 
96
104
  assert_equal 88, ret_value[:local_var][:param1]
105
+ assert_equal nil, ret_value[:local_var][:param2]
106
+ end
107
+
108
+ def test_track_local_var_when_event_is_return
109
+ SourceRoute.enable 'nonsense_with_params' do
110
+ events :return
111
+ output_include_local_variables
112
+ end
113
+
114
+ SampleApp.new.nonsense_with_params(88)
115
+ assert_equal 1, @wrapper.tp_attrs_results.size
116
+
117
+ ret_value_for_return_event = @wrapper.tp_attrs_results.last
118
+ assert_equal 88, ret_value_for_return_event[:local_var][:param1]
119
+ assert_equal 5, ret_value_for_return_event[:local_var][:param2]
97
120
  end
98
121
 
99
122
  def test_show_instance_vars
@@ -101,21 +124,23 @@ module SourceRoute
101
124
  output_include_instance_variables
102
125
  end
103
126
 
104
- SampleApp.new(:cool).nonsense_with_instance_var
127
+ SampleApp.new('ins sure').nonsense_with_instance_var
105
128
 
106
129
  assert_equal 2, @wrapper.tp_attrs_results.size
107
130
  ret_value = @wrapper.tp_attrs_results.pop
108
131
 
109
- assert_equal :cool, ret_value[:instance_var][:@cool]
132
+ assert_equal 'ins sure', ret_value[:instance_var][:@sample]
110
133
  end
111
134
 
112
- # Nothing has tested really
113
- def test_html_format_output
114
- @source_route = SourceRoute.enable 'nonsense' do
135
+ # Nothing has tested really when run rake cause ENV['ignore_html_generation'] was set to true
136
+ def test_html_format_output_only
137
+ @source_route = SourceRoute.enable do
138
+ defined_class 'SampleApp'
115
139
  output_include_instance_variables
140
+ output_include_local_variables
116
141
  end
117
142
 
118
- SampleApp.new(:cool).nonsense_with_instance_var
143
+ SampleApp.new.init_cool_app
119
144
 
120
145
  if ENV['ignore_html_generation'] == 'true'
121
146
  # do nothing. it was set in Rakefile, so rake test will not generate html file
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.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - raykin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-23 00:00:00.000000000 Z
11
+ date: 2014-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  description: Wrapper of TracePoint.
84
98
  email:
85
99
  - raykincoldxiao@gmail.com
@@ -105,7 +119,7 @@ files:
105
119
  - test/sample_app.rb
106
120
  - test/test_helper.rb
107
121
  - test/wrapper_test.rb
108
- homepage: ''
122
+ homepage: http://github.com/raykin/source-route
109
123
  licenses:
110
124
  - MIT
111
125
  metadata: {}
@@ -117,7 +131,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
117
131
  requirements:
118
132
  - - ">="
119
133
  - !ruby/object:Gem::Version
120
- version: '0'
134
+ version: '2'
121
135
  required_rubygems_version: !ruby/object:Gem::Requirement
122
136
  requirements:
123
137
  - - ">="
@@ -134,4 +148,3 @@ test_files:
134
148
  - test/sample_app.rb
135
149
  - test/test_helper.rb
136
150
  - test/wrapper_test.rb
137
- has_rdoc: