big_ear 0.0.1
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 +7 -0
- data/lib/big_ear.rb +46 -0
- metadata +43 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 4ac9063421e53a9ca9a9c02892162bcb6fc014efb7aa07f240475133ce06d3c3
|
|
4
|
+
data.tar.gz: ea35a08cdc7b150d64781f27d127d90f118bc658b48ac5b7fcf53551afcd6be5
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 294e2a52b7573114fa4021774e2b40a61e74b0a6d0b6818deaa8f8b3e3a3a5d4eabe27e516a4ac28b5e74965a8337d1203bf4b752b3277b03891ab032debe058
|
|
7
|
+
data.tar.gz: b0caaef32dcbf5e7acb1e61fcb87b244fe5a82d123f764498f8f1734554065a7a3b8ce5b75f38fd1b52f7de24ce96821c4d65fa4c151d0c21a1a8cca2ff3c18b
|
data/lib/big_ear.rb
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
module BigEar
|
|
2
|
+
|
|
3
|
+
# Records an object's method calls
|
|
4
|
+
# during execution of given block
|
|
5
|
+
#
|
|
6
|
+
# @param object [Object] object whose method calls to be recorded
|
|
7
|
+
# @param block [Proc] block to be executed during recording
|
|
8
|
+
# @return [Proc] Proc which returns the recording logs when called
|
|
9
|
+
def self.record_proc(object)
|
|
10
|
+
proc do
|
|
11
|
+
recorder = BigEar::Recorder.new(object)
|
|
12
|
+
recorder.start
|
|
13
|
+
yield
|
|
14
|
+
|
|
15
|
+
recorder.stop
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class Recorder
|
|
20
|
+
def initialize(object)
|
|
21
|
+
@log = []
|
|
22
|
+
@object = object
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def start
|
|
26
|
+
@trace = TracePoint.trace(:return) do |tp|
|
|
27
|
+
next unless tp.self.object_id == @object.object_id
|
|
28
|
+
params_values = tp.self.method(tp.method_id).parameters.map(&:last).map do |param|
|
|
29
|
+
{param => tp.binding.local_variable_get(param)}
|
|
30
|
+
end
|
|
31
|
+
@log.append("method: #{tp.callee_id}, params: #{params_values}, ret_val: #{tp.return_value}")
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def stop
|
|
36
|
+
@trace&.disable
|
|
37
|
+
@trace = nil
|
|
38
|
+
|
|
39
|
+
log = @log
|
|
40
|
+
@log = []
|
|
41
|
+
|
|
42
|
+
log
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: big_ear
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Mert Buran
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-04-27 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Record method calls of your object and inspect them
|
|
14
|
+
email: buranmert@gmail.com
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/big_ear.rb
|
|
20
|
+
homepage: http://github.com/buranmert/big-ear
|
|
21
|
+
licenses:
|
|
22
|
+
- MIT
|
|
23
|
+
metadata: {}
|
|
24
|
+
post_install_message:
|
|
25
|
+
rdoc_options: []
|
|
26
|
+
require_paths:
|
|
27
|
+
- lib
|
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
34
|
+
requirements:
|
|
35
|
+
- - ">="
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
requirements: []
|
|
39
|
+
rubygems_version: 3.0.3
|
|
40
|
+
signing_key:
|
|
41
|
+
specification_version: 4
|
|
42
|
+
summary: Method calls recorder
|
|
43
|
+
test_files: []
|