jinyu-debug-tools 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/utils/method_debugger.rb +30 -3
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 04b28856f2f9ef3e5b61da97680c38fbf488406b
4
- data.tar.gz: aadcf61df0c48701a89575e4cefe3f5280588aa5
3
+ metadata.gz: a4eca0e3f24fc6606bb268362ec4a2b488140129
4
+ data.tar.gz: ca076f86be97abb5e451f98d0cc7f1e764488aac
5
5
  SHA512:
6
- metadata.gz: cabcae7d7efbf8ca7067eed783143ef8cc051b07db5959d08fd73782662661adaba505eb0f713e3e4670c3561af91231cfd739f42edbff6aba179fc2567a0717
7
- data.tar.gz: c1eff24c9ae617bf7f86d632eeb79f925f5c35af54af29f2c00d9f48acd0fa368cd3bc7f32f70c44a90c6420b7ba2867bdc1672f54eefb96c6a8e478907d2f40
6
+ metadata.gz: 622d37fb9dbd6e5c851388100c9c0698ab3961c4faadb8595ac16d3eed8ca804326d3fd55c4ba765101214b7512ec66a91b19140ba082989d0cae92b95b416bc
7
+ data.tar.gz: 3d3e0ef9fceaeb99b0190a690addc972d540480e3a5adcd4a91010db6f61eb221fb0ffedc8dc406a1e54b0578153f42128f9ac19005a643b2f96488030e65fda
@@ -1,9 +1,10 @@
1
- module JinyuDebugTools
2
1
  module MethodDebugger
3
2
  def self.included(sub_klass)
3
+
4
4
  sub_klass.class_eval do
5
5
  @@__debug_log = []
6
6
  @@__method_table = Hash.new{|hash, key| hash[key] = {}}
7
+ @@__singleton_method_table = Hash.new{|hash, key| hash[key] = {}}
7
8
 
8
9
  def self.method_added(method_name)
9
10
  return if @@__method_table[self][method_name]
@@ -17,14 +18,40 @@ module JinyuDebugTools
17
18
  define_method(method_name) do |*method_args, &block|
18
19
  caller_file = caller[0].split('/').last
19
20
  puts "jinyu.debug: #{caller_file} calls #{method_name}, #{method_args.map(&:class)}"
21
+ #p "#{self}.send(__#{method_name})"
22
+ #puts "\n"
20
23
 
21
- # hit 'super' keyword issue, check with https://stackoverflow.com/questions/18448831
22
- # remove line below
24
+ # hit 'super' keyword issue, check with
25
+ #https://stackoverflow.com/questions/18448831/calling-method-in-parent-class-from-subclass-methods-in-ruby
23
26
  #self.send("__#{method_name}".to_sym, *method_args, &block)
24
27
 
25
28
  self_class.instance_method("__#{method_name}".to_sym).bind(self).call(*method_args, &block)
26
29
  end
27
30
  end
31
+
32
+ def self.singleton_method_added(method_name)
33
+ return if method_name == :singleton_method_added
34
+
35
+ return if @@__singleton_method_table[self][method_name]
36
+ @@__singleton_method_table[self][method_name] = true
37
+
38
+ return if method_name.to_s.match(/^__/)
39
+
40
+ singleton_class.class_eval do
41
+ alias_method "__#{method_name}".to_sym, method_name
42
+ self_class = self
43
+
44
+ define_method(method_name) do |*method_args, &block|
45
+ caller_file = caller[0].split('/').last
46
+ puts "jinyu.debug: #{caller_file} calls #{method_name}, #{method_args.map(&:class)}"
47
+
48
+ # hit 'super' keyword issue, check with
49
+ #https://stackoverflow.com/questions/18448831/calling-method-in-parent-class-from-subclass-methods-in-ruby #self.send("__#{method_name}".to_sym, *method_args, &block)
50
+
51
+ self_class.instance_method("__#{method_name}".to_sym).bind(self).call(*method_args, &block)
52
+ end
53
+ end
54
+ end
28
55
  end
29
56
  end
30
57
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jinyu-debug-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yukai Jin