tapping_device 0.5.6 → 0.5.7
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 +4 -4
- data/Gemfile.lock +8 -4
- data/lib/tapping_device.rb +1 -0
- data/lib/tapping_device/output/payload.rb +24 -37
- data/lib/tapping_device/payload.rb +1 -1
- data/lib/tapping_device/trackers/initialization_tracker.rb +10 -1
- data/lib/tapping_device/version.rb +1 -1
- data/tapping_device.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28a848cfef98c43315488230c1593aba48ef1b3ee91dc7a495a6cee7cb406771
|
4
|
+
data.tar.gz: 30601c6039343512d3d7c157bd0c8e5645b8005aa37a4b365458018cb477c2d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2540416f3d4ece8dfb76ee567030d3f4ab9da497c9ae97e9d7418b952d7ce0552453aad33278344ce683dc89a393244d74aef20bc6c6cf9847f0198911999a20
|
7
|
+
data.tar.gz: b417c4c17f18a152ce0bbc4135657bc41cb90b70788b971debb4242a1d35a9189c21621420af5f5bf06e9aa76148f9a49c6e2fb786000769a193c57765de45d1
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
tapping_device (0.5.
|
4
|
+
tapping_device (0.5.7)
|
5
5
|
activerecord (>= 5.2)
|
6
6
|
activesupport
|
7
|
+
pastel
|
7
8
|
pry
|
8
9
|
|
9
10
|
GEM
|
@@ -21,15 +22,17 @@ GEM
|
|
21
22
|
tzinfo (~> 1.1)
|
22
23
|
zeitwerk (~> 2.2, >= 2.2.2)
|
23
24
|
coderay (1.1.3)
|
24
|
-
concurrent-ruby (1.1.
|
25
|
+
concurrent-ruby (1.1.7)
|
25
26
|
database_cleaner (1.7.0)
|
26
27
|
diff-lcs (1.3)
|
27
28
|
docile (1.3.2)
|
28
|
-
i18n (1.8.
|
29
|
+
i18n (1.8.5)
|
29
30
|
concurrent-ruby (~> 1.0)
|
30
31
|
json (2.3.0)
|
31
32
|
method_source (1.0.0)
|
32
|
-
minitest (5.14.
|
33
|
+
minitest (5.14.2)
|
34
|
+
pastel (0.8.0)
|
35
|
+
tty-color (~> 0.5)
|
33
36
|
pry (0.13.1)
|
34
37
|
coderay (~> 1.1)
|
35
38
|
method_source (~> 1.0)
|
@@ -54,6 +57,7 @@ GEM
|
|
54
57
|
simplecov-html (0.10.2)
|
55
58
|
sqlite3 (1.4.1)
|
56
59
|
thread_safe (0.3.6)
|
60
|
+
tty-color (0.5.2)
|
57
61
|
tzinfo (1.2.7)
|
58
62
|
thread_safe (~> 0.1)
|
59
63
|
zeitwerk (2.4.0)
|
data/lib/tapping_device.rb
CHANGED
@@ -1,17 +1,24 @@
|
|
1
|
+
require "pastel"
|
2
|
+
|
1
3
|
class TappingDevice
|
2
4
|
module Output
|
3
5
|
class Payload < Payload
|
4
6
|
UNDEFINED = "[undefined]"
|
7
|
+
PRIVATE_MARK = " (private)"
|
8
|
+
|
9
|
+
PASTEL = Pastel.new
|
10
|
+
PASTEL.alias_color(:orange, :bright_red, :bright_yellow)
|
5
11
|
|
6
12
|
alias :raw_arguments :arguments
|
7
13
|
alias :raw_return_value :return_value
|
8
14
|
|
9
15
|
def method_name(options = {})
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
16
|
+
name = ":#{super(options)}"
|
17
|
+
|
18
|
+
name += " [#{tag}]" if tag
|
19
|
+
name += PRIVATE_MARK if is_private_call?
|
20
|
+
|
21
|
+
name
|
15
22
|
end
|
16
23
|
|
17
24
|
def arguments(options = {})
|
@@ -22,29 +29,13 @@ class TappingDevice
|
|
22
29
|
generate_string_result(raw_return_value, options[:inspect])
|
23
30
|
end
|
24
31
|
|
25
|
-
COLOR_CODES = {
|
26
|
-
green: 10,
|
27
|
-
yellow: 11,
|
28
|
-
blue: 12,
|
29
|
-
megenta: 13,
|
30
|
-
cyan: 14,
|
31
|
-
orange: 214
|
32
|
-
}
|
33
|
-
|
34
|
-
COLORS = COLOR_CODES.each_with_object({}) do |(name, code), hash|
|
35
|
-
hash[name] = "\u001b[38;5;#{code}m"
|
36
|
-
end.merge(
|
37
|
-
reset: "\u001b[0m",
|
38
|
-
nocolor: ""
|
39
|
-
)
|
40
|
-
|
41
32
|
PAYLOAD_ATTRIBUTES = {
|
42
|
-
method_name: {symbol: "", color:
|
43
|
-
location: {symbol: "from:", color:
|
44
|
-
return_value: {symbol: "=>", color:
|
45
|
-
arguments: {symbol: "<=", color:
|
46
|
-
ivar_changes: {symbol: "changes:\n", color:
|
47
|
-
defined_class: {symbol: "#", color:
|
33
|
+
method_name: {symbol: "", color: :bright_blue},
|
34
|
+
location: {symbol: "from:", color: :green},
|
35
|
+
return_value: {symbol: "=>", color: :magenta},
|
36
|
+
arguments: {symbol: "<=", color: :orange},
|
37
|
+
ivar_changes: {symbol: "changes:\n", color: :blue},
|
38
|
+
defined_class: {symbol: "#", color: :yellow}
|
48
39
|
}
|
49
40
|
|
50
41
|
PAYLOAD_ATTRIBUTES.each do |attribute, attribute_options|
|
@@ -57,7 +48,7 @@ class TappingDevice
|
|
57
48
|
call_result = send("original_#{attribute}", options)
|
58
49
|
|
59
50
|
if options[:colorize]
|
60
|
-
|
51
|
+
PASTEL.send(color, call_result)
|
61
52
|
else
|
62
53
|
call_result
|
63
54
|
end
|
@@ -87,7 +78,7 @@ class TappingDevice
|
|
87
78
|
return unless arg_name
|
88
79
|
|
89
80
|
arg_name = ":#{arg_name}"
|
90
|
-
arg_name =
|
81
|
+
arg_name = PASTEL.orange(arg_name) if options[:colorize]
|
91
82
|
msg = "Passed as #{arg_name} in '#{defined_class(options)}##{method_name(options)}' at #{location(options)}\n"
|
92
83
|
msg += " > #{method_head}\n" if with_method_head
|
93
84
|
msg
|
@@ -109,12 +100,12 @@ class TappingDevice
|
|
109
100
|
after = generate_string_result(value_changes[:after], options[:inspect])
|
110
101
|
|
111
102
|
if options[:colorize]
|
112
|
-
ivar =
|
113
|
-
before =
|
114
|
-
after =
|
103
|
+
ivar = PASTEL.orange(ivar)
|
104
|
+
before = PASTEL.bright_blue(before.to_s)
|
105
|
+
after = PASTEL.bright_blue(after.to_s)
|
115
106
|
end
|
116
107
|
|
117
|
-
" #{ivar}: #{before
|
108
|
+
" #{ivar}: #{before} => #{after}"
|
118
109
|
end.join("\n")
|
119
110
|
end
|
120
111
|
|
@@ -130,10 +121,6 @@ class TappingDevice
|
|
130
121
|
|
131
122
|
private
|
132
123
|
|
133
|
-
def value_with_color(value, color)
|
134
|
-
"#{COLORS[color]}#{value}#{COLORS[:reset]}"
|
135
|
-
end
|
136
|
-
|
137
124
|
def generate_string_result(obj, inspect)
|
138
125
|
case obj
|
139
126
|
when Array
|
@@ -2,7 +2,7 @@ class TappingDevice
|
|
2
2
|
class Payload < Hash
|
3
3
|
ATTRS = [
|
4
4
|
:target, :receiver, :method_name, :method_object, :arguments, :return_value, :filepath, :line_number,
|
5
|
-
:defined_class, :trace, :tp, :ivar_changes, :is_private_call?
|
5
|
+
:defined_class, :trace, :tag, :tp, :ivar_changes, :is_private_call?
|
6
6
|
]
|
7
7
|
|
8
8
|
ATTRS.each do |attr|
|
@@ -34,7 +34,16 @@ class TappingDevice
|
|
34
34
|
method_name = tp.callee_id
|
35
35
|
|
36
36
|
if @is_active_record_model
|
37
|
-
|
37
|
+
# ActiveRecord redefines model classes' .new method,
|
38
|
+
# so instead of calling Model#initialize, it'll actually call Model.new
|
39
|
+
# see https://github.com/rails/rails/blob/master/activerecord/lib/active_record/inheritance.rb#L50
|
40
|
+
method_name == :new &&
|
41
|
+
receiver.is_a?(Class) &&
|
42
|
+
# this checks if the model class is the target class or a subclass of it
|
43
|
+
receiver.ancestors.include?(target) &&
|
44
|
+
# Model.new triggers both c_return and return events. so we should only return in 1 type of the events
|
45
|
+
# otherwise the callback will be triggered twice
|
46
|
+
tp.event == :return
|
38
47
|
else
|
39
48
|
method_name == :initialize && receiver.is_a?(target)
|
40
49
|
end
|
data/tapping_device.gemspec
CHANGED
@@ -34,6 +34,7 @@ Gem::Specification.new do |spec|
|
|
34
34
|
|
35
35
|
spec.add_dependency "pry" # for using Method#source in MutationTracker
|
36
36
|
spec.add_dependency "activesupport"
|
37
|
+
spec.add_dependency "pastel"
|
37
38
|
|
38
39
|
spec.add_development_dependency "sqlite3", ">= 1.3.6"
|
39
40
|
spec.add_development_dependency "database_cleaner"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tapping_device
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- st0012
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pastel
|
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'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: sqlite3
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|