trace_location 0.9.3.1 → 0.11.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 +7 -5
- data/exe/trace_location +6 -0
- data/lib/trace_location.rb +2 -1
- data/lib/trace_location/cli.rb +59 -0
- data/lib/trace_location/collector.rb +13 -8
- data/lib/trace_location/config.rb +1 -1
- data/lib/trace_location/report.rb +1 -0
- data/lib/trace_location/version.rb +1 -1
- data/trace_location.gemspec +3 -4
- metadata +10 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 010e65cd3a2447cb0816fd31bb62eec1acb6546a0cc2d8667df523027d24abd4
|
4
|
+
data.tar.gz: 9bce85eda13a6836c0195d05265dcaf9794d4f2356d6a0b5ad5cf25d915db5b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 274ae1e802b7eb65e81cabd20fc66bd7b8ba2c7427e6eb2e5e6dee0a9415350a26cad2827f670151b9e94329b4702bca8086432b94179c20b15e48fca3a5265e
|
7
|
+
data.tar.gz: 367ae84388dd7a5b331ed780b99e6539a9f895aa5be06acdde803501a1bef8f24c155b7334031d4dc6314272332511773dfe4139ac825c63c53df5dc346c6c91
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,25 +1,21 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
trace_location (0.
|
5
|
-
binding_of_caller
|
4
|
+
trace_location (0.11.0)
|
6
5
|
method_source
|
7
6
|
|
8
7
|
GEM
|
9
8
|
remote: https://rubygems.org/
|
10
9
|
specs:
|
11
10
|
ast (2.4.0)
|
12
|
-
binding_of_caller (0.8.0)
|
13
|
-
debug_inspector (>= 0.0.1)
|
14
|
-
debug_inspector (0.0.3)
|
15
11
|
diff-lcs (1.3)
|
16
12
|
jaro_winkler (1.5.2)
|
17
|
-
method_source (0.
|
13
|
+
method_source (1.0.0)
|
18
14
|
parallel (1.17.0)
|
19
15
|
parser (2.6.3.0)
|
20
16
|
ast (~> 2.4.0)
|
21
17
|
rainbow (3.0.0)
|
22
|
-
rake (
|
18
|
+
rake (13.0.1)
|
23
19
|
rspec (3.8.0)
|
24
20
|
rspec-core (~> 3.8.0)
|
25
21
|
rspec-expectations (~> 3.8.0)
|
@@ -54,4 +50,4 @@ DEPENDENCIES
|
|
54
50
|
trace_location!
|
55
51
|
|
56
52
|
BUNDLED WITH
|
57
|
-
2.
|
53
|
+
2.1.4
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# TraceLocation
|
2
2
|
|
3
|
+
[](https://travis-ci.org/yhirano55/trace_location)
|
4
|
+
|
3
5
|
TraceLocation helps you get tracing the source location of codes, and helps you can get reading the huge open souce libraries in Ruby.
|
4
6
|
|
5
7
|
## Installation
|
@@ -37,9 +39,9 @@ Then you can get logs like this: [.md](https://github.com/yhirano55/trace_locati
|
|
37
39
|
|
38
40
|
| name | content | example |
|
39
41
|
|:-----|:--------|:--------|
|
40
|
-
| format | `:
|
41
|
-
| match | Regexp for allow list |
|
42
|
-
| ignore | Regexp for deny list | `/bootsnap\|activesupport/` |
|
42
|
+
| format | `:md`, `:log`, `:csv` (default: `:md`) | `:md` |
|
43
|
+
| match | Regexp, Symbol, String or Array for allow list | `[:activerecord, :activesupport]` |
|
44
|
+
| ignore | Regexp, Symbol, String or Array for deny list | `/bootsnap\|activesupport/` |
|
43
45
|
|
44
46
|
## More examples
|
45
47
|
|
@@ -69,7 +71,7 @@ Results: [.md](https://github.com/yhirano55/trace_location/blob/master/examples/
|
|
69
71
|
```ruby
|
70
72
|
class User < ApplicationRecord
|
71
73
|
# temporary surrounding with TraceLocation#trace
|
72
|
-
|
74
|
+
TraceLocation.trace(format: :md, ignore: /activesupport/) do
|
73
75
|
has_secure_password
|
74
76
|
end
|
75
77
|
```
|
@@ -87,7 +89,7 @@ class BooksController < ApplicationController
|
|
87
89
|
@books = Book.all
|
88
90
|
|
89
91
|
# temporary surrounding with TraceLocation#trace
|
90
|
-
TraceLocation.trace(format: :
|
92
|
+
TraceLocation.trace(format: :md, ignore: /activesupport|rbenv|concurrent-ruby/) do
|
91
93
|
render json: @books
|
92
94
|
end
|
93
95
|
end
|
data/exe/trace_location
ADDED
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
|
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module TraceLocation
|
4
|
+
class CLI
|
5
|
+
attr_reader :argv
|
6
|
+
|
7
|
+
def initialize(argv)
|
8
|
+
@argv = argv
|
9
|
+
end
|
10
|
+
|
11
|
+
def run
|
12
|
+
opt = OptionParser.new
|
13
|
+
opt.on('-f FORMAT', '--format=FORMAT', 'Report format (default: :md)', &:to_sym)
|
14
|
+
opt.on('-m REGEXP', '--match=REGEXP') { |str| Regexp.new(str) }
|
15
|
+
opt.on('-i REGEXP', '--ignore=REGEXP') { |str| Regexp.new(str) }
|
16
|
+
opt.on('-d DIR', '--dest-dir=DIR')
|
17
|
+
opt.on('-e code')
|
18
|
+
|
19
|
+
params = {}
|
20
|
+
opt.order!(argv, into: params)
|
21
|
+
params.transform_keys! { |k| k.to_s.gsub('-', '_').to_sym }
|
22
|
+
|
23
|
+
if code = params.delete(:e)
|
24
|
+
exec_code code, params
|
25
|
+
else
|
26
|
+
file = argv.shift
|
27
|
+
unless file
|
28
|
+
puts opt.help
|
29
|
+
exit 1
|
30
|
+
end
|
31
|
+
|
32
|
+
exec_command file, params
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def exec_command(cmd, params)
|
39
|
+
path =
|
40
|
+
if File.exist?(cmd)
|
41
|
+
cmd
|
42
|
+
else
|
43
|
+
`which #{cmd}`.chomp
|
44
|
+
end
|
45
|
+
|
46
|
+
$PROGRAM_NAME = cmd
|
47
|
+
|
48
|
+
TraceLocation.trace(params) do
|
49
|
+
load path
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def exec_code(code, params)
|
54
|
+
TraceLocation.trace(params) do
|
55
|
+
eval code
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -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].match?(/\A(?:<internal:.+>|\(eval\))\z/)
|
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
|
)
|
@@ -81,8 +86,8 @@ module TraceLocation
|
|
81
86
|
end
|
82
87
|
|
83
88
|
def remove_indent(source)
|
84
|
-
indent = source
|
85
|
-
source.
|
89
|
+
indent = source[/\A(\s*)/, 1]
|
90
|
+
source.gsub(/^#{indent}/, '')
|
86
91
|
end
|
87
92
|
end
|
88
93
|
end
|
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.11.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-08-12 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,7 +71,9 @@ 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
|
87
|
-
|
74
|
+
- shioi.mm@gmail.com
|
75
|
+
executables:
|
76
|
+
- trace_location
|
88
77
|
extensions: []
|
89
78
|
extra_rdoc_files: []
|
90
79
|
files:
|
@@ -114,7 +103,9 @@ files:
|
|
114
103
|
- examples/rendering_process/result.csv
|
115
104
|
- examples/rendering_process/result.log
|
116
105
|
- examples/rendering_process/result.md
|
106
|
+
- exe/trace_location
|
117
107
|
- lib/trace_location.rb
|
108
|
+
- lib/trace_location/cli.rb
|
118
109
|
- lib/trace_location/collector.rb
|
119
110
|
- lib/trace_location/config.rb
|
120
111
|
- lib/trace_location/event.rb
|
@@ -139,14 +130,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
139
130
|
requirements:
|
140
131
|
- - ">="
|
141
132
|
- !ruby/object:Gem::Version
|
142
|
-
version: 2.
|
133
|
+
version: 2.6.0
|
143
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
135
|
requirements:
|
145
136
|
- - ">="
|
146
137
|
- !ruby/object:Gem::Version
|
147
138
|
version: '0'
|
148
139
|
requirements: []
|
149
|
-
rubygems_version: 3.
|
140
|
+
rubygems_version: 3.1.2
|
150
141
|
signing_key:
|
151
142
|
specification_version: 4
|
152
143
|
summary: helps you get tracing the source location of codes
|