caller_log 0.1.0 → 0.1.2

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
  SHA1:
3
- metadata.gz: 170210b9d7d1c0fe0f6caf0b358cfbccec98e54c
4
- data.tar.gz: fd1c8f249534e9d62ff28e55d1ebd1014832ded1
3
+ metadata.gz: dce8296b1ca697f272b3dae5e064f8899d64cecb
4
+ data.tar.gz: 44c6a29b8c78d936864511c9e6695a95b0b0f06c
5
5
  SHA512:
6
- metadata.gz: 81309e4dc08389dc2f29bd8d45d43c1375e96aa739c4694db5adeeb84fb94bd9d7b0dba99b4a98bdd5e229babdad073f863f75c1df244026aba7bf06d460302d
7
- data.tar.gz: 5ad9e14f9dcf5a4324372c54ed072a7425081506f7d007fb1574f722abc119f78df32cd45d9143ad7c6fbd3a9ac283efdcb705b12258cd61424c025a212893b3
6
+ metadata.gz: 9768b0ee6e4019c3670b70811e0053193865439f150c17cc756933969d4e919d66ab05e950f3a3d48f4a574e909ae0470207ccdf5c3690591ab77fe8c08ccace
7
+ data.tar.gz: 5b1718a7b4075dd31c857b3eb3101d5af8e1231799f877b9d432e8abddb8aeef92f3de94a445a0c384c415af260be66c57539ba62ca4693f3be9df9f852bf734
data/caller_log.gemspec CHANGED
@@ -24,7 +24,6 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "rake", "~> 10.0"
25
25
  spec.add_development_dependency "minitest", "~> 5.0"
26
26
 
27
- spec.add_dependency "dcr"
28
27
  spec.add_dependency "binding_of_callers"
29
28
  spec.add_dependency "nokogiri", "~> 1.7.1"
30
29
  end
data/lib/caller_log.rb CHANGED
@@ -1,29 +1,51 @@
1
1
  require 'caller_log/version'
2
2
  require 'caller_log/log'
3
3
  require 'binding_of_callers'
4
- require 'dcr'
5
4
 
6
5
  module CallerLog
7
6
  class << self
8
7
 
9
- def instance *args
8
+ def log *args
10
9
  raise ArgumentError,
11
10
  "wrong number of arguments (given #{args.count}, expected more than 1)" if args.count < 2
12
11
  log_file = args.pop
13
- modules = Array args
12
+ objects = Array args
14
13
 
15
14
  log = Log.new log_file
16
15
 
17
- modules.each do |mod|
18
- mod.instance_methods(false).each do |method_id|
19
- Dcr.instance mod, method_id do |method, *para, &blk|
20
- record = OpenStruct.new time: Time.now, module: mod, method_id: method_id, callers: binding.of_callers[2..-1]
16
+ objects.each do |obj|
17
+
18
+ callee = calling obj
19
+
20
+ obj.instance_methods(false).each do |method_id|
21
+ o_method = ref_old method_id
22
+ obj.send :alias_method, o_method, method_id
23
+ obj.send :define_method, method_id, &-> *para, &blk {
24
+ record = OpenStruct.new time: Time.now, callee: "#{callee}##{method_id}", callers: binding.of_callers[1..-1]
21
25
  log.puts record
22
- method.call *para, &blk
23
- end
26
+ self.send o_method, *para, &blk
27
+ }
28
+ end if obj.is_a? Module
29
+
30
+ obj.methods(false).each do |method_id|
31
+ o_method = obj.method method_id
32
+ obj.singleton_class.send :define_method, method_id, &-> *para, &blk {
33
+ record = OpenStruct.new time: Time.now, callee: "#{callee}.#{method_id}", callers: binding.of_callers[1..-1]
34
+ log.puts record
35
+ o_method.call *para, &blk
36
+ }
24
37
  end
38
+
25
39
  end
26
40
  end
41
+
42
+ def calling obj
43
+ Module === obj ? "#{obj}" : "<#{obj.class}:#{obj.object_id}>"
44
+ end
45
+
46
+ def ref_old method_id
47
+ "#{method_id}_caller_log"
48
+ end
27
49
  end
28
50
 
29
51
  end
@@ -57,14 +57,16 @@ EOHTML
57
57
  time = record.time.strftime "%F %T"
58
58
  call = Nokogiri::HTML::DocumentFragment.parse <<-EOHTML
59
59
  <li id='call-#{record.object_id}' class='thread-#{Thread.current.object_id} call'>
60
- <span class='time'>#{time}</span><span class='class_and_method'>#{record.module}##{record.method_id}</span>
60
+ <span class='time'>#{time}</span><span class='class_and_method'>#{record.callee}</span>
61
61
  </li>
62
62
  EOHTML
63
63
  base.at_css('.calls') << call
64
64
  end
65
65
 
66
66
  def new_stack_fragment record
67
- callers = record.callers.map do |c|
67
+ callers = record.callers.reject do |c|
68
+ c.file =~ /caller_log\/lib\/caller_log\.rb/
69
+ end.map do |c|
68
70
  class_and_method = CGI::escapeHTML "#{c.klass}#{c.call_symbol}#{c.frame_env}"
69
71
  "<p><span class='class_and_method'>#{class_and_method}</span><span class='location'>#{c.file}:#{c.line}</span></p>"
70
72
  end.join
@@ -3,18 +3,27 @@
3
3
  <head>
4
4
  <meta charset='utf-8'/>
5
5
  <style>
6
+ html,body {
7
+ margin: 0;
8
+ padding: 0;
9
+ background-color: #E91E63;
10
+ }
6
11
  ul {
7
12
  padding-left: 0;
13
+ background-color: white;
14
+ margin-bottom: 0;
8
15
  }
9
16
 
10
17
  li {
11
18
  list-style: none;
12
19
  margin-bottom: .8rem;
20
+ padding-left: 1rem;
13
21
  }
14
22
 
15
23
  ul.threads li {
16
24
  float: left;
17
25
  margin-top: -.5rem;
26
+ color: white;
18
27
  }
19
28
 
20
29
  ul.calls {
@@ -23,17 +32,19 @@ ul.calls {
23
32
  top: 1rem;
24
33
  bottom: 0;
25
34
  width: 18rem;
35
+ padding: 1rem 0 1rem 0;
26
36
  overflow: auto;
27
37
  }
28
38
 
29
39
  ul.stacks {
30
40
  position: fixed;
31
- left: 20rem;
41
+ left: 18rem;
32
42
  top: 1rem;
33
43
  bottom: 0;
34
44
  margin-top: 2rem;
45
+ padding: 1rem 0 1rem 0;
35
46
  overflow: auto;
36
- width: calc(100% - 20rem);
47
+ width: calc(100% - 18rem);
37
48
  }
38
49
 
39
50
  p {
@@ -61,6 +72,10 @@ ul.stacks li {
61
72
  ul.stacks li.show {
62
73
  display: block;
63
74
  }
75
+
76
+ .highlight {
77
+ color: #03A9F4;
78
+ }
64
79
  </style>
65
80
  </head>
66
81
  <body>
@@ -96,12 +111,19 @@ ul.stacks li.show {
96
111
  document.querySelector('.' + call_li.id).classList.add('show');
97
112
  }
98
113
 
114
+ function highlight(call_li){
115
+ var curr_highlight = document.querySelector('.highlight');
116
+ curr_highlight && curr_highlight.classList.remove('highlight');
117
+ call_li.classList.add('highlight');
118
+ return true;
119
+ }
120
+
99
121
  var body = document.getElementsByTagName('body')[0];
100
122
 
101
123
  body.addEventListener('click', function(e){
102
124
  var target = e.target;
103
125
  target.type == 'checkbox' && target.checked && show_call(target.value) || hide_call(target.value);
104
- e.target.parentElement.classList.contains('call') && toggle_stack(e.target.parentElement);
126
+ e.target.parentElement.classList.contains('call') && highlight(e.target.parentElement) && toggle_stack(e.target.parentElement);
105
127
  }, false);
106
128
 
107
129
  })();
@@ -1,3 +1,3 @@
1
1
  module CallerLog
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caller_log
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ken
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-30 00:00:00.000000000 Z
11
+ date: 2017-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.0'
55
- - !ruby/object:Gem::Dependency
56
- name: dcr
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: binding_of_callers
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -134,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
120
  version: '0'
135
121
  requirements: []
136
122
  rubyforge_project:
137
- rubygems_version: 2.6.8
123
+ rubygems_version: 2.5.2
138
124
  signing_key:
139
125
  specification_version: 4
140
126
  summary: Log every call to a object