method_call_tree 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/Gemfile.lock +1 -1
- data/README.md +28 -0
- data/lib/method_call_tree/version.rb +1 -1
- data/lib/method_call_tree.rb +17 -8
- data.tar.gz.sig +0 -0
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 484aa4c05a41bb984d586cbf8e5f620aaa1ea816fbff780df434027f574fc9a3
|
4
|
+
data.tar.gz: 0bf6d62ebcfe2a9264d34b76d11915b3d162a47fa203e0e29bf960ff1624472d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bcac72e5de0ea7244f44c73c0dbc6d976c5122db0ed395f6468dc22f328f39da7bcc2faf0908eea99419086e20ef42841bf66871fb559e62959b4cb788be122
|
7
|
+
data.tar.gz: 153746635ecbf35047ef88fd6e34e9720a17c96b71b6f1e7cd1b795dd6775eb21cd519d537102f703e1327171aaca53ee4816064e65101d39098337b55775167
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -48,6 +48,34 @@ Foo::foo
|
|
48
48
|
└───── Foo::hoge
|
49
49
|
```
|
50
50
|
|
51
|
+
`args` options enable
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
require 'method_call_tree'
|
55
|
+
def fibonacci(a = 1, b = 0)
|
56
|
+
return if a > 10
|
57
|
+
fibonacci(a + b, a)
|
58
|
+
end
|
59
|
+
|
60
|
+
tree = MethodCallTree.create(args: true) do
|
61
|
+
fibonacci
|
62
|
+
end
|
63
|
+
|
64
|
+
puts tree
|
65
|
+
```
|
66
|
+
|
67
|
+
result
|
68
|
+
|
69
|
+
```
|
70
|
+
Object::fibonacci(a = 1, b = 0)
|
71
|
+
└───── Object::fibonacci(a = 1, b = 1)
|
72
|
+
└───── Object::fibonacci(a = 2, b = 1)
|
73
|
+
└───── Object::fibonacci(a = 3, b = 2)
|
74
|
+
└───── Object::fibonacci(a = 5, b = 3)
|
75
|
+
└───── Object::fibonacci(a = 8, b = 5)
|
76
|
+
└───── Object::fibonacci(a = 13, b = 8)
|
77
|
+
```
|
78
|
+
|
51
79
|
## License
|
52
80
|
|
53
81
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/lib/method_call_tree.rb
CHANGED
@@ -1,17 +1,24 @@
|
|
1
1
|
require 'method_call_tree/version'
|
2
2
|
|
3
3
|
class MethodCallTree
|
4
|
+
GET_ARGUMENTS = <<-'TEXT'.freeze
|
5
|
+
method(__method__).parameters.map { |_t, v|
|
6
|
+
"#{v} = #{eval(v.to_s).inspect}"
|
7
|
+
}.join(', ')
|
8
|
+
TEXT
|
9
|
+
|
4
10
|
SPACE_SIZE = 8
|
5
|
-
T_LINE = '├─────'
|
6
|
-
I_LINE = '│'
|
7
|
-
L_LINE = '└─────'
|
11
|
+
T_LINE = '├─────'.freeze
|
12
|
+
I_LINE = '│'.freeze
|
13
|
+
L_LINE = '└─────'.freeze
|
8
14
|
|
9
|
-
def self.create(&block)
|
10
|
-
new(&block)
|
15
|
+
def self.create(options = {}, &block)
|
16
|
+
new(options, &block)
|
11
17
|
end
|
12
18
|
|
13
|
-
def initialize
|
14
|
-
@
|
19
|
+
def initialize(options)
|
20
|
+
@args = options[:args]
|
21
|
+
@tree = {}
|
15
22
|
@queue = []
|
16
23
|
|
17
24
|
tracer.enable { yield }
|
@@ -34,7 +41,9 @@ class MethodCallTree
|
|
34
41
|
TracePoint.new(:call, :return) do |tp|
|
35
42
|
case tp.event
|
36
43
|
when :call
|
37
|
-
key = "#{tp.defined_class}::#{tp.method_id}
|
44
|
+
key = "#{tp.defined_class}::#{tp.method_id}"
|
45
|
+
key += "(#{tp.binding.eval(GET_ARGUMENTS)})" if @args
|
46
|
+
key += "_#{id}"
|
38
47
|
id += 1
|
39
48
|
|
40
49
|
call_stack.inject(@tree, :[])[key] = {}
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|