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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 885539b68748c37932f81fb7b15c611a67ac7d50ddc73a7d9b4b4e1c60437ba3
4
- data.tar.gz: 63322f15c3f3cdb714bd79d5f84bae2bbf1d45416f078a7f92f6e059ae903699
3
+ metadata.gz: 484aa4c05a41bb984d586cbf8e5f620aaa1ea816fbff780df434027f574fc9a3
4
+ data.tar.gz: 0bf6d62ebcfe2a9264d34b76d11915b3d162a47fa203e0e29bf960ff1624472d
5
5
  SHA512:
6
- metadata.gz: 490d6c5e57c3ba6cfe0e0a377152745cbf61a01d85d5f3f3caac30d4b8d773bb5acf5e7321b79023432c03e3ee98a6ab460f3beba92c22d55dfe5c1ff46a8415
7
- data.tar.gz: be8961febdd7bdb4894fcc8cc18feae9858c0474da2abc9a0d3271238110a5b450d02388109f152ed8c7754514a36ec74f8ba54a1f22eda850fe9e48bc4562df
6
+ metadata.gz: 1bcac72e5de0ea7244f44c73c0dbc6d976c5122db0ed395f6468dc22f328f39da7bcc2faf0908eea99419086e20ef42841bf66871fb559e62959b4cb788be122
7
+ data.tar.gz: 153746635ecbf35047ef88fd6e34e9720a17c96b71b6f1e7cd1b795dd6775eb21cd519d537102f703e1327171aaca53ee4816064e65101d39098337b55775167
checksums.yaml.gz.sig CHANGED
Binary file
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- method_call_tree (1.0.1)
4
+ method_call_tree (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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).
@@ -1,3 +1,3 @@
1
1
  class MethodCallTree
2
- VERSION = "1.0.1"
2
+ VERSION = '1.1.0'
3
3
  end
@@ -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
- @tree = Hash.new
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}_#{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
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: method_call_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shuichi Tamayose
metadata.gz.sig CHANGED
Binary file