source_route 0.0.2 → 0.0.3

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: 67d1a63084f0e5b6a0f2e7fb6f066d8b02510590
4
- data.tar.gz: f7cc2c6ddc3632cde00f74a97b634834df307154
3
+ metadata.gz: c9a1ba833697d52c2138c558b5c94ec6dec3516d
4
+ data.tar.gz: 1635e5de83aaf367d91b9867c68b38fc269df07e
5
5
  SHA512:
6
- metadata.gz: 001a12df5c3bbb0c3ae80d92f1661732ddbd44689f72cb214b84a3b55e01d266282273e094347ed795816fe3d66fc524247ffa4b3a6a3a5d4cce87f8da70b3b2
7
- data.tar.gz: 8bd9da28ab7372e981ca605e63402f6bd7637db273be83c920db5b3548a9c6b0af01082b78cf6762a230fda79678be491586ec156168251b5b17195ce6c84a21
6
+ metadata.gz: cf1d68cce07fb6b22ba6e0a01b297ec383ae3bc82cd5ce98404207b649e0abaab1d5be2b491a59ad80f3c288cd1a2377fa0c816602c452239bc9142735d74be2
7
+ data.tar.gz: cefc0e26d83f5f9488f203ff12d28224cd02d7473b6af0bc07db6596f8a5d6f1773f8d119ff6abb9ee94ad68f2d51e9bff8d6ddbb32eeb7bbeea16d350d660bf
data/README.md CHANGED
@@ -35,21 +35,4 @@ Or install it yourself as:
35
35
 
36
36
  ### TODO
37
37
 
38
- Following code is a good sample that track file running sequence, how to change it into a good code design and merge into the gem
39
-
40
- ```ruby
41
-
42
- files = []
43
- tp = TracePoint.new(:line) do |tp|
44
- if tp.path =~ /bole_api/
45
- unless files.include? tp.path
46
- puts "#{tp.path}".inspect
47
- files.push(tp.path)
48
- end
49
- end
50
- end
51
- tp.enable
52
-
53
- ```
54
-
55
- It's better to add html output format, 'cause it can be kept.
38
+ Add debug option to provider more verbose messages of what has happened
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # copy this file content to bin/rails, then run ./bin/rails s, it should show init files in order
4
+
5
+ require 'source_route'
6
+
7
+ SourceRoute.enable do
8
+ file_paths = []
9
+ event :line
10
+ path 'your_rails_application_root_dir_name'
11
+ output_format do |tp|
12
+ unless file_paths.include? tp.path
13
+ puts tp.path
14
+ file_paths.push(tp.path)
15
+ end
16
+ end
17
+ end
18
+
19
+ # The above source route block defines similar trace point feature as following
20
+ # files = []
21
+ # tp = TracePoint.new(:line) do |tp|
22
+ # if tp.path =~ /your_rails_application_root_dir_name/
23
+ # unless files.include? tp.path
24
+ # puts "#{tp.path}".inspect
25
+ # files.push(tp.path)
26
+ # end
27
+ # end
28
+ # end
29
+ # tp.enable
30
+
31
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
32
+ require_relative '../config/boot'
33
+ require 'rails/commands'
@@ -29,27 +29,26 @@ module SourceRoute
29
29
  @collect_data
30
30
  end
31
31
 
32
- # must run build before it # not a good design
33
- def output
32
+ def output(tp_ins)
34
33
 
35
- format = @output_config[:output_format].to_sym
34
+ format = @output_config[:output_format]
35
+ format = format.to_sym if format.respond_to? :to_sym
36
36
 
37
37
  case format
38
38
  when :none
39
39
  # do nothing
40
- when :console
40
+ when :console # need @collect_data
41
41
  console_put
42
42
  when :html
43
43
  # I cant solve the problem: to generate html at the end,
44
44
  # I have to know when the application is end
45
45
  when :test
46
46
  # do nothing at now
47
- when :Proc
48
- # customize not defined yet
49
- # format.call(tp)
47
+ when Proc
48
+ format.call(tp_ins)
50
49
  else
51
50
  klass = "SourceRoute::Formats::#{format.to_s.capitalize}"
52
- ::SourceRoute.const_get(klass).render(self, trace_point_instance)
51
+ ::SourceRoute.const_get(klass).render(self, tp_ins)
53
52
  end
54
53
  end
55
54
 
@@ -1,3 +1,3 @@
1
1
  module SourceRoute
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
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(events: :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,
@@ -27,6 +27,7 @@ module SourceRoute
27
27
  @conditions.events = Array(v).map(&:to_sym) unless v.nil?
28
28
  end
29
29
  alias :event :events
30
+
30
31
  def set_result_config(value)
31
32
  unless value.is_a? Hash
32
33
  conditions.result_config = value
@@ -34,15 +35,15 @@ module SourceRoute
34
35
  end
35
36
 
36
37
  def output_format(data = nil, &block)
37
- conditions.result_config[:output_format] = if data.nil?
38
+ conditions.result_config[:output_format] = if block_given?
38
39
  block
39
40
  else
40
41
  data
41
42
  end
42
43
  end
43
44
 
44
- def selected_attrs(data)
45
- conditions.result_config[:selected_attrs] = [data].flatten
45
+ def selected_attrs(*attr)
46
+ conditions.result_config[:selected_attrs] = Array(attr)
46
47
  end
47
48
 
48
49
  def output_include_local_variables
@@ -79,9 +80,12 @@ module SourceRoute
79
80
  end
80
81
  next if positive_break
81
82
 
82
- ret_data = tp_result.build(tp)
83
- tp_attrs_results.push(ret_data)
84
- tp_result.output
83
+ unless conditions[:result_config][:output_format].is_a? Proc
84
+ ret_data = tp_result.build(tp)
85
+ tp_attrs_results.push(ret_data)
86
+ end
87
+
88
+ tp_result.output(tp)
85
89
  end
86
90
  track.enable
87
91
  self.tp = track
data/lib/source_route.rb CHANGED
@@ -21,7 +21,7 @@ module SourceRoute
21
21
  end
22
22
 
23
23
  def disable
24
- wrapper.reset
24
+ wrapper.tp.disable
25
25
  end
26
26
 
27
27
  def enable(match = nil, &block)
data/test/test_helper.rb CHANGED
@@ -5,5 +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 'pry'
9
- # require 'pry-byebug'
8
+ require 'pry'
9
+ require 'pry-byebug'
data/test/wrapper_test.rb CHANGED
@@ -39,7 +39,7 @@ module SourceRoute
39
39
  assert @wrapper.tp_attrs_results.size > 0
40
40
  end
41
41
 
42
- def test_match_class_name_by_block_define
42
+ def test_match_class_name
43
43
  @source_route = SourceRoute.enable do
44
44
  defined_class 'SampleApp'
45
45
  end
@@ -67,12 +67,19 @@ module SourceRoute
67
67
  assert_equal 0, @wrapper.tp_attrs_results.size
68
68
  end
69
69
 
70
- def test_source_route_with_block
71
- SourceRoute.trace method_id: 'nonsense', output_format: :test do
70
+ def test_source_route_with_block_only
71
+ paths = []
72
+ SourceRoute.enable 'nonsense' do
72
73
  SampleApp.new.nonsense
74
+ output_format do |tp|
75
+ paths.push tp.path
76
+ end
73
77
  end
74
- assert_equal 1, @wrapper.tp_attrs_results.size
75
- refute @wrapper.tp.enabled?
78
+ SampleApp.new.nonsense
79
+
80
+ assert_equal 0, @wrapper.tp_attrs_results.size
81
+ assert_equal 1, paths.size
82
+ assert_includes paths.first, 'sample_app'
76
83
  end
77
84
 
78
85
  def test_trace_without_first_hash_option
@@ -94,6 +101,7 @@ module SourceRoute
94
101
  def test_show_local_variables
95
102
  SourceRoute.enable 'nonsense_with_params' do
96
103
  output_include_local_variables
104
+ output_format :console
97
105
  end
98
106
 
99
107
  SampleApp.new.nonsense_with_params(88)
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.2
4
+ version: 0.0.3
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-03 00:00:00.000000000 Z
11
+ date: 2014-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -107,6 +107,7 @@ files:
107
107
  - LICENSE.txt
108
108
  - README.md
109
109
  - Rakefile
110
+ - examples/show_init_files_when_rails_server_start.rb
110
111
  - lib/source_route.rb
111
112
  - lib/source_route/formats/html.rb
112
113
  - lib/source_route/formats/html_template.slim
@@ -148,3 +149,4 @@ test_files:
148
149
  - test/sample_app.rb
149
150
  - test/test_helper.rb
150
151
  - test/wrapper_test.rb
152
+ has_rdoc: