trace_location 0.9.1 → 0.9.2
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/Gemfile.lock +1 -7
- data/lib/trace_location/collector.rb +70 -47
- data/lib/trace_location/event.rb +10 -12
- data/lib/trace_location/generator/csv.rb +1 -1
- data/lib/trace_location/generator/log.rb +1 -1
- data/lib/trace_location/generator/markdown.rb +3 -10
- data/lib/trace_location/version.rb +1 -1
- data/trace_location.gemspec +0 -1
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17ca486d486f5139ac8b32b55092baa1d9ff2d3c8845c3021d9a9314d7d5a177
|
4
|
+
data.tar.gz: f1f5ccba6018672a27d52d5927f73fb6ce9f63a32a14d2075e1fc96da7f158ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92af182afecc84fa9c3f41bcee7ed928e5a90e2427397dd1aaf7786d67c29e98baf203f615bcddcf6e8a17bb3a0ffe04495c20bfcfbcb7f402c17ee0edede6fe
|
7
|
+
data.tar.gz: 65153552b73e1ed496f660707344488a1179a2018cae5c41b73d6847d227b7a19ce9acf9a9f907edd4503f5a669ba6e704237a906b9e25f1bcb37223b7024ac4
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
trace_location (0.9.
|
4
|
+
trace_location (0.9.2)
|
5
5
|
binding_of_caller
|
6
|
-
pry
|
7
6
|
|
8
7
|
GEM
|
9
8
|
remote: https://rubygems.org/
|
@@ -11,17 +10,12 @@ GEM
|
|
11
10
|
ast (2.4.0)
|
12
11
|
binding_of_caller (0.8.0)
|
13
12
|
debug_inspector (>= 0.0.1)
|
14
|
-
coderay (1.1.2)
|
15
13
|
debug_inspector (0.0.3)
|
16
14
|
diff-lcs (1.3)
|
17
15
|
jaro_winkler (1.5.2)
|
18
|
-
method_source (0.9.2)
|
19
16
|
parallel (1.17.0)
|
20
17
|
parser (2.6.3.0)
|
21
18
|
ast (~> 2.4.0)
|
22
|
-
pry (0.12.2)
|
23
|
-
coderay (~> 1.1.0)
|
24
|
-
method_source (~> 0.9.0)
|
25
19
|
rainbow (3.0.0)
|
26
20
|
rake (12.3.2)
|
27
21
|
rspec (3.8.0)
|
@@ -7,55 +7,78 @@ module TraceLocation
|
|
7
7
|
require_relative 'event'
|
8
8
|
Result = Struct.new(:events, :return_value)
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
10
|
+
class << self
|
11
|
+
def collect(match:, ignore:, &block)
|
12
|
+
events = []
|
13
|
+
hierarchy = 0
|
14
|
+
id = 0
|
15
|
+
cache = {}
|
16
|
+
|
17
|
+
tracer = TracePoint.new(:call, :return) do |trace_point|
|
18
|
+
next if match && !trace_point.path.to_s.match?(/#{match}/)
|
19
|
+
next if ignore && trace_point.path.to_s.match?(/#{ignore}/)
|
20
|
+
|
21
|
+
id += 1
|
22
|
+
caller_path, caller_lineno = trace_point.binding.of_caller(2).source_location
|
23
|
+
location_cache_key = "#{caller_path}:#{caller_lineno}"
|
24
|
+
|
25
|
+
mes = extract_method_from(trace_point)
|
26
|
+
|
27
|
+
case trace_point.event
|
28
|
+
when :call
|
29
|
+
cache[location_cache_key] = hierarchy
|
30
|
+
|
31
|
+
events << Event.new(
|
32
|
+
id: id,
|
33
|
+
event: trace_point.event,
|
34
|
+
path: trace_point.path,
|
35
|
+
lineno: trace_point.lineno,
|
36
|
+
caller_path: caller_path,
|
37
|
+
caller_lineno: caller_lineno,
|
38
|
+
owner: mes.owner,
|
39
|
+
name: mes.name,
|
40
|
+
source: remove_indent(mes.source),
|
41
|
+
hierarchy: hierarchy,
|
42
|
+
is_module: trace_point.self.is_a?(Module)
|
43
|
+
)
|
44
|
+
|
45
|
+
hierarchy += 1
|
46
|
+
when :return
|
47
|
+
hierarchy = cache[location_cache_key] || hierarchy
|
48
|
+
|
49
|
+
events << Event.new(
|
50
|
+
id: id,
|
51
|
+
event: trace_point.event,
|
52
|
+
path: trace_point.path,
|
53
|
+
lineno: trace_point.lineno,
|
54
|
+
caller_path: caller_path,
|
55
|
+
caller_lineno: caller_lineno,
|
56
|
+
owner: mes.owner,
|
57
|
+
name: mes.name,
|
58
|
+
source: remove_indent(mes.source),
|
59
|
+
hierarchy: hierarchy,
|
60
|
+
is_module: trace_point.self.is_a?(Module)
|
61
|
+
)
|
62
|
+
end
|
55
63
|
end
|
64
|
+
return_value = tracer.enable { block.call }
|
65
|
+
Result.new(events, return_value)
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def extract_method_from(trace_point)
|
71
|
+
if trace_point.self.is_a?(Module)
|
72
|
+
::Module.instance_method(:method).bind(trace_point.self).call(trace_point.method_id)
|
73
|
+
else
|
74
|
+
::Kernel.instance_method(:method).bind(trace_point.self).call(trace_point.method_id)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def remove_indent(source)
|
79
|
+
indent = source.split("\n").first.match(/\A(\s+).+\z/)[1]
|
80
|
+
source.split("\n").map { |line| line.gsub(/\A#{indent}/, '') }.join("\n")
|
56
81
|
end
|
57
|
-
return_value = tracer.enable { block.call }
|
58
|
-
Result.new(events, return_value)
|
59
82
|
end
|
60
83
|
end
|
61
84
|
end
|
data/lib/trace_location/event.rb
CHANGED
@@ -3,18 +3,20 @@
|
|
3
3
|
module TraceLocation
|
4
4
|
class Event # :nodoc:
|
5
5
|
CLASS_FORMAT = /\A#<(?:Class|refinement)\:([A-Za-z0-9\:]+).*>\z/.freeze
|
6
|
-
attr_reader :id, :event, :path, :lineno, :caller_path, :caller_lineno, :
|
6
|
+
attr_reader :id, :event, :path, :lineno, :caller_path, :caller_lineno, :owner, :name, :source, :hierarchy, :is_module
|
7
7
|
|
8
|
-
def initialize(id:, event:, path:, lineno:, caller_path:, caller_lineno:,
|
8
|
+
def initialize(id:, event:, path:, lineno:, caller_path:, caller_lineno:, owner:, name:, source:, hierarchy:, is_module:)
|
9
9
|
@id = id
|
10
10
|
@event = event
|
11
11
|
@path = path
|
12
12
|
@lineno = lineno
|
13
13
|
@caller_path = caller_path
|
14
14
|
@caller_lineno = caller_lineno
|
15
|
-
@
|
16
|
-
@
|
15
|
+
@owner = owner
|
16
|
+
@name = name
|
17
|
+
@source = source
|
17
18
|
@hierarchy = hierarchy.to_i
|
19
|
+
@is_module = is_module
|
18
20
|
end
|
19
21
|
|
20
22
|
def valid?
|
@@ -33,14 +35,10 @@ module TraceLocation
|
|
33
35
|
event == :return
|
34
36
|
end
|
35
37
|
|
36
|
-
def
|
37
|
-
match =
|
38
|
-
|
39
|
-
|
40
|
-
"#{match[1]}.#{method_id}"
|
41
|
-
else
|
42
|
-
"#{defined_class}##{method_id}"
|
43
|
-
end
|
38
|
+
def owner_with_name
|
39
|
+
match = owner.to_s.match(CLASS_FORMAT)
|
40
|
+
separator = is_module ? '.' : '#'
|
41
|
+
match ? "#{match[1]}#{separator}#{name}" : "#{owner}#{separator}#{name}"
|
44
42
|
end
|
45
43
|
end
|
46
44
|
end
|
@@ -5,7 +5,7 @@ require 'csv'
|
|
5
5
|
module TraceLocation
|
6
6
|
module Generator
|
7
7
|
class Csv < Base # :nodoc:
|
8
|
-
ATTRIBUTES = %w[id event path lineno caller_path caller_lineno
|
8
|
+
ATTRIBUTES = %w[id event path lineno caller_path caller_lineno owner_with_name hierarchy].freeze
|
9
9
|
|
10
10
|
def initialize(events, return_value, options)
|
11
11
|
super
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'pry'
|
4
|
-
|
5
3
|
module TraceLocation
|
6
4
|
module Generator
|
7
5
|
class Markdown < Base # :nodoc:
|
@@ -36,25 +34,20 @@ module TraceLocation
|
|
36
34
|
MARKDOWN
|
37
35
|
|
38
36
|
events.select(&:call?).each do |e|
|
39
|
-
pm = Pry::Method.from_str(e.method_str)
|
40
|
-
next if pm.nil?
|
41
|
-
|
42
37
|
path = e.path.to_s.gsub(%r{#{gems_dir}/}, '')
|
43
38
|
caller_path = e.caller_path.to_s.gsub(%r{#{gems_dir}/}, '')
|
44
39
|
io.write <<~MARKDOWN
|
45
40
|
<details open>
|
46
41
|
<summary>#{path}:#{e.lineno}</summary>
|
47
42
|
|
48
|
-
##### #{
|
43
|
+
##### #{e.owner_with_name}
|
49
44
|
|
50
|
-
|
51
|
-
#{
|
45
|
+
```ruby
|
46
|
+
#{e.source}
|
52
47
|
# called from #{caller_path}:#{e.caller_lineno}
|
53
48
|
```
|
54
49
|
</details>
|
55
50
|
MARKDOWN
|
56
|
-
rescue StandardError
|
57
|
-
next
|
58
51
|
end
|
59
52
|
end
|
60
53
|
end
|
data/trace_location.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trace_location
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yoshiyuki Hirano
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-06-
|
11
|
+
date: 2019-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: binding_of_caller
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: pry
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: bundler
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|