trace_location 0.9.3 → 0.10.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/.rubocop.yml +1 -1
- data/.travis.yml +8 -2
- data/Gemfile.lock +4 -8
- data/README.md +43 -316
- data/examples/active_record_establish_connection/result.csv +265 -0
- data/examples/active_record_establish_connection/result.log +271 -0
- data/examples/active_record_establish_connection/result.md +2279 -0
- data/examples/active_record_validation_process/result.csv +11 -0
- data/examples/active_record_validation_process/result.log +17 -0
- data/examples/active_record_validation_process/result.md +69 -0
- data/examples/has_secure_password/result.csv +41 -0
- data/examples/has_secure_password/result.log +47 -0
- data/examples/has_secure_password/result.md +395 -0
- data/examples/lifecycle_of_rails_application/result.csv +2769 -0
- data/examples/lifecycle_of_rails_application/result.log +2775 -0
- data/examples/lifecycle_of_rails_application/result.md +21437 -0
- data/examples/rendering_process/result.csv +617 -0
- data/examples/rendering_process/result.log +623 -0
- data/examples/rendering_process/result.md +4414 -0
- data/lib/trace_location.rb +2 -1
- data/lib/trace_location/collector.rb +19 -10
- data/lib/trace_location/config.rb +3 -3
- data/lib/trace_location/generator/csv.rb +12 -2
- data/lib/trace_location/generator/log.rb +6 -7
- data/lib/trace_location/generator/markdown.rb +5 -4
- data/lib/trace_location/report.rb +1 -0
- data/lib/trace_location/version.rb +1 -1
- data/trace_location.gemspec +3 -4
- metadata +21 -19
- data/CHANGELOG.md +0 -19
data/lib/trace_location.rb
CHANGED
@@ -21,7 +21,8 @@ module TraceLocation # :nodoc:
|
|
21
21
|
Report.build(result.events, result.return_value, options).generate
|
22
22
|
true
|
23
23
|
rescue StandardError => e
|
24
|
-
$
|
24
|
+
$stderr.puts "Failure: TraceLocation got an unexpected error."
|
25
|
+
$stderr.puts e.full_message
|
25
26
|
false
|
26
27
|
end
|
27
28
|
|
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'binding_of_caller'
|
4
3
|
require 'method_source'
|
5
4
|
|
6
5
|
module TraceLocation
|
@@ -14,16 +13,22 @@ module TraceLocation
|
|
14
13
|
hierarchy = 0
|
15
14
|
id = 0
|
16
15
|
cache = {}
|
16
|
+
method_source_cache = {}
|
17
17
|
|
18
18
|
tracer = TracePoint.new(:call, :return) do |trace_point|
|
19
|
-
next if match && !trace_point.path.to_s.match?(/#{match}/)
|
20
|
-
next if ignore && trace_point.path.to_s.match?(/#{ignore}/)
|
19
|
+
next if match && !trace_point.path.to_s.match?(/#{Array(match).join('|')}/)
|
20
|
+
next if ignore && trace_point.path.to_s.match?(/#{Array(ignore).join('|')}/)
|
21
21
|
|
22
22
|
id += 1
|
23
|
-
|
23
|
+
caller_loc = caller_locations(2, 1)[0]
|
24
|
+
caller_path = caller_loc.absolute_path
|
25
|
+
caller_lineno = caller_loc.lineno
|
24
26
|
location_cache_key = "#{caller_path}:#{caller_lineno}"
|
25
27
|
|
26
28
|
mes = extract_method_from(trace_point)
|
29
|
+
next if mes.source_location[0] == '<internal:prelude>'
|
30
|
+
|
31
|
+
method_source = method_source_cache[mes] ||= remove_indent(mes.source)
|
27
32
|
|
28
33
|
case trace_point.event
|
29
34
|
when :call
|
@@ -38,7 +43,7 @@ module TraceLocation
|
|
38
43
|
caller_lineno: caller_lineno,
|
39
44
|
owner: mes.owner,
|
40
45
|
name: mes.name,
|
41
|
-
source:
|
46
|
+
source: method_source,
|
42
47
|
hierarchy: hierarchy,
|
43
48
|
is_module: trace_point.self.is_a?(Module)
|
44
49
|
)
|
@@ -56,7 +61,7 @@ module TraceLocation
|
|
56
61
|
caller_lineno: caller_lineno,
|
57
62
|
owner: mes.owner,
|
58
63
|
name: mes.name,
|
59
|
-
source:
|
64
|
+
source: method_source,
|
60
65
|
hierarchy: hierarchy,
|
61
66
|
is_module: trace_point.self.is_a?(Module)
|
62
67
|
)
|
@@ -70,15 +75,19 @@ module TraceLocation
|
|
70
75
|
|
71
76
|
def extract_method_from(trace_point)
|
72
77
|
if trace_point.self.is_a?(Module)
|
73
|
-
::Module.instance_method(:method)
|
78
|
+
::Module.instance_method(:method)
|
79
|
+
.bind(trace_point.self)
|
80
|
+
.call(trace_point.method_id)
|
74
81
|
else
|
75
|
-
::Kernel.instance_method(:method)
|
82
|
+
::Kernel.instance_method(:method)
|
83
|
+
.bind(trace_point.self)
|
84
|
+
.call(trace_point.method_id)
|
76
85
|
end
|
77
86
|
end
|
78
87
|
|
79
88
|
def remove_indent(source)
|
80
|
-
indent = source
|
81
|
-
source.
|
89
|
+
indent = source[/\A(\s*)/, 1]
|
90
|
+
source.gsub(/^#{indent}/, '')
|
82
91
|
end
|
83
92
|
end
|
84
93
|
end
|
@@ -2,12 +2,12 @@
|
|
2
2
|
|
3
3
|
module TraceLocation
|
4
4
|
class Config # :nodoc:
|
5
|
-
attr_accessor :
|
5
|
+
attr_accessor :current_dir, :dest_dir, :default_format
|
6
6
|
|
7
7
|
def initialize
|
8
|
-
@
|
8
|
+
@current_dir = Dir.pwd
|
9
9
|
@dest_dir = Dir.pwd
|
10
|
-
@default_format = :
|
10
|
+
@default_format = :md
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -9,6 +9,7 @@ module TraceLocation
|
|
9
9
|
|
10
10
|
def initialize(events, return_value, options)
|
11
11
|
super
|
12
|
+
@current_dir = ::TraceLocation.config.current_dir
|
12
13
|
@dest_dir = options.fetch(:dest_dir) { ::TraceLocation.config.dest_dir }
|
13
14
|
@file_path = File.join(@dest_dir, "trace_location-#{Time.now.strftime('%Y%m%d%H%m%s')}.csv")
|
14
15
|
end
|
@@ -21,7 +22,7 @@ module TraceLocation
|
|
21
22
|
|
22
23
|
private
|
23
24
|
|
24
|
-
attr_reader :events, :return_value, :dest_dir, :file_path
|
25
|
+
attr_reader :events, :return_value, :current_dir, :dest_dir, :file_path
|
25
26
|
|
26
27
|
def setup_dir
|
27
28
|
FileUtils.mkdir_p(dest_dir)
|
@@ -32,7 +33,16 @@ module TraceLocation
|
|
32
33
|
csv << ATTRIBUTES
|
33
34
|
|
34
35
|
events.each do |event|
|
35
|
-
csv <<
|
36
|
+
csv << [
|
37
|
+
event.id,
|
38
|
+
event.event,
|
39
|
+
event.path.to_s.gsub(%r{#{current_dir}/}, ''),
|
40
|
+
event.lineno,
|
41
|
+
event.caller_path.to_s.gsub(%r{#{current_dir}/}, ''),
|
42
|
+
event.caller_lineno,
|
43
|
+
event.owner_with_name,
|
44
|
+
event.hierarchy
|
45
|
+
]
|
36
46
|
end
|
37
47
|
end
|
38
48
|
end
|
@@ -11,7 +11,7 @@ module TraceLocation
|
|
11
11
|
|
12
12
|
def initialize(events, return_value, options)
|
13
13
|
super
|
14
|
-
@
|
14
|
+
@current_dir = ::TraceLocation.config.current_dir
|
15
15
|
@dest_dir = options.fetch(:dest_dir) { ::TraceLocation.config.dest_dir }
|
16
16
|
@current = Time.now
|
17
17
|
@filename = "trace_location-#{@current.strftime('%Y%m%d%H%m%s')}.log"
|
@@ -26,7 +26,7 @@ module TraceLocation
|
|
26
26
|
|
27
27
|
private
|
28
28
|
|
29
|
-
attr_reader :events, :return_value, :
|
29
|
+
attr_reader :events, :return_value, :current_dir, :dest_dir, :current, :filename, :file_path
|
30
30
|
|
31
31
|
def setup_dir
|
32
32
|
FileUtils.mkdir_p(dest_dir)
|
@@ -46,12 +46,11 @@ module TraceLocation
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def format_events(events)
|
49
|
-
events.select(&:valid?).map do |
|
50
|
-
indent = indent(
|
51
|
-
|
52
|
-
path = e.path.to_s.gsub(%r{#{gems_dir}/}, '')
|
49
|
+
events.select(&:valid?).map do |event|
|
50
|
+
indent = indent(event.hierarchy)
|
51
|
+
path = event.path.to_s.gsub(%r{#{current_dir}/}, '')
|
53
52
|
|
54
|
-
%(#{indent}#{event} #{path}:#{
|
53
|
+
%(#{indent}#{EVENTS[event.event]} #{path}:#{event.lineno} [#{event.owner_with_name}])
|
55
54
|
end
|
56
55
|
end
|
57
56
|
|
@@ -5,7 +5,7 @@ module TraceLocation
|
|
5
5
|
class Markdown < Base # :nodoc:
|
6
6
|
def initialize(events, return_value, options)
|
7
7
|
super
|
8
|
-
@
|
8
|
+
@current_dir = ::TraceLocation.config.current_dir
|
9
9
|
@dest_dir = options.fetch(:dest_dir) { ::TraceLocation.config.dest_dir }
|
10
10
|
@current = Time.now
|
11
11
|
@filename = "trace_location-#{@current.strftime('%Y%m%d%H%m%s')}.md"
|
@@ -20,7 +20,7 @@ module TraceLocation
|
|
20
20
|
|
21
21
|
private
|
22
22
|
|
23
|
-
attr_reader :events, :return_value, :
|
23
|
+
attr_reader :events, :return_value, :current_dir, :dest_dir, :current, :filename, :file_path
|
24
24
|
|
25
25
|
def setup_dir
|
26
26
|
FileUtils.mkdir_p(dest_dir)
|
@@ -34,8 +34,9 @@ module TraceLocation
|
|
34
34
|
MARKDOWN
|
35
35
|
|
36
36
|
events.select(&:call?).each do |e|
|
37
|
-
path = e.path.to_s.gsub(%r{#{
|
38
|
-
caller_path = e.caller_path.to_s.gsub(%r{#{
|
37
|
+
path = e.path.to_s.gsub(%r{#{current_dir}/}, '')
|
38
|
+
caller_path = e.caller_path.to_s.gsub(%r{#{current_dir}/}, '')
|
39
|
+
|
39
40
|
io.write <<~MARKDOWN
|
40
41
|
<details open>
|
41
42
|
<summary>#{path}:#{e.lineno}</summary>
|
data/trace_location.gemspec
CHANGED
@@ -7,8 +7,8 @@ require 'trace_location/version'
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = 'trace_location'
|
9
9
|
s.version = TraceLocation::VERSION
|
10
|
-
s.authors = ['Yoshiyuki Hirano']
|
11
|
-
s.email = ['yhirano@me.com']
|
10
|
+
s.authors = ['Yoshiyuki Hirano', 'Misaki Shioi']
|
11
|
+
s.email = ['yhirano@me.com', 'shioi.mm@gmail.com']
|
12
12
|
s.homepage = 'https://github.com/yhirano55/trace_location'
|
13
13
|
s.summary = 'helps you get tracing the source location of codes'
|
14
14
|
s.description = %(TraceLocation helps you get tracing the source location of codes, and helps you can get reading the huge open souce libraries in Ruby)
|
@@ -21,9 +21,8 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.bindir = 'exe'
|
22
22
|
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
23
|
s.require_paths = ['lib']
|
24
|
-
s.required_ruby_version = '>= 2.
|
24
|
+
s.required_ruby_version = '>= 2.6.0'
|
25
25
|
|
26
|
-
s.add_dependency 'binding_of_caller'
|
27
26
|
s.add_dependency 'method_source'
|
28
27
|
|
29
28
|
s.add_development_dependency 'bundler'
|
metadata
CHANGED
@@ -1,29 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trace_location
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yoshiyuki Hirano
|
8
|
+
- Misaki Shioi
|
8
9
|
autorequire:
|
9
10
|
bindir: exe
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2020-06-20 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: binding_of_caller
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
14
|
- !ruby/object:Gem::Dependency
|
28
15
|
name: method_source
|
29
16
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,6 +71,7 @@ description: TraceLocation helps you get tracing the source location of codes, a
|
|
84
71
|
helps you can get reading the huge open souce libraries in Ruby
|
85
72
|
email:
|
86
73
|
- yhirano@me.com
|
74
|
+
- shioi.mm@gmail.com
|
87
75
|
executables: []
|
88
76
|
extensions: []
|
89
77
|
extra_rdoc_files: []
|
@@ -92,7 +80,6 @@ files:
|
|
92
80
|
- ".rspec"
|
93
81
|
- ".rubocop.yml"
|
94
82
|
- ".travis.yml"
|
95
|
-
- CHANGELOG.md
|
96
83
|
- Gemfile
|
97
84
|
- Gemfile.lock
|
98
85
|
- LICENSE.txt
|
@@ -100,6 +87,21 @@ files:
|
|
100
87
|
- Rakefile
|
101
88
|
- bin/console
|
102
89
|
- bin/setup
|
90
|
+
- examples/active_record_establish_connection/result.csv
|
91
|
+
- examples/active_record_establish_connection/result.log
|
92
|
+
- examples/active_record_establish_connection/result.md
|
93
|
+
- examples/active_record_validation_process/result.csv
|
94
|
+
- examples/active_record_validation_process/result.log
|
95
|
+
- examples/active_record_validation_process/result.md
|
96
|
+
- examples/has_secure_password/result.csv
|
97
|
+
- examples/has_secure_password/result.log
|
98
|
+
- examples/has_secure_password/result.md
|
99
|
+
- examples/lifecycle_of_rails_application/result.csv
|
100
|
+
- examples/lifecycle_of_rails_application/result.log
|
101
|
+
- examples/lifecycle_of_rails_application/result.md
|
102
|
+
- examples/rendering_process/result.csv
|
103
|
+
- examples/rendering_process/result.log
|
104
|
+
- examples/rendering_process/result.md
|
103
105
|
- lib/trace_location.rb
|
104
106
|
- lib/trace_location/collector.rb
|
105
107
|
- lib/trace_location/config.rb
|
@@ -125,14 +127,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
125
127
|
requirements:
|
126
128
|
- - ">="
|
127
129
|
- !ruby/object:Gem::Version
|
128
|
-
version: 2.
|
130
|
+
version: 2.6.0
|
129
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
132
|
requirements:
|
131
133
|
- - ">="
|
132
134
|
- !ruby/object:Gem::Version
|
133
135
|
version: '0'
|
134
136
|
requirements: []
|
135
|
-
rubygems_version: 3.
|
137
|
+
rubygems_version: 3.1.2
|
136
138
|
signing_key:
|
137
139
|
specification_version: 4
|
138
140
|
summary: helps you get tracing the source location of codes
|
data/CHANGELOG.md
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
## v0.3.0
|
2
|
-
|
3
|
-
- Log path is shorten
|
4
|
-
- Use gems_dir instead of root_dir
|
5
|
-
- Don't collect not including gems_dir
|
6
|
-
- Fix Regexp
|
7
|
-
|
8
|
-
## v0.2.0
|
9
|
-
|
10
|
-
- Refactoring: Separate Collector/Report/Generator
|
11
|
-
- Display class method or instance method
|
12
|
-
|
13
|
-
## v0.1.1
|
14
|
-
|
15
|
-
- Update README
|
16
|
-
|
17
|
-
## v0.1.0
|
18
|
-
|
19
|
-
- Initial Release
|