ariadne 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ariadne/helpers/text.rb +51 -0
- data/lib/ariadne/helpers/value_format.rb +43 -0
- data/lib/ariadne/log.rb +31 -23
- data/lib/ariadne/parameter.rb +0 -37
- data/lib/ariadne/seam.rb +50 -24
- data/lib/ariadne/thread.rb +63 -21
- data/lib/ariadne/version.rb +1 -1
- metadata +4 -17
- data/lib/ariadne/text.rb +0 -43
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d15963f0e72fcd20333f6227ced3e4dba5e3d5a7c2cc295440dcc98c9bb863a
|
4
|
+
data.tar.gz: bd90b66bad183442d7661fd72566ef11223d45f705817bcae2b2026efc928a3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42c4370c8b426696d7b336fc42e40c60509569f60e1260a37aa952c1ee013b8a0ef94784032907574d256eb53071e5d8563ec5a9539b555e5abb08d4165b4bff
|
7
|
+
data.tar.gz: 30d1d3b263dee8c331d9f8d23b8bf8b9e422fd66b7f24a9488f2b4c3b8dc464a461201a0820475231628904a9a071d3ee496e8cd5cb27b0803818ecf2fce4bab
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ariadne
|
4
|
+
module Helpers
|
5
|
+
module Text
|
6
|
+
class Text < String
|
7
|
+
COLORS = %w[
|
8
|
+
black
|
9
|
+
red
|
10
|
+
green
|
11
|
+
yellow
|
12
|
+
blue
|
13
|
+
magenta
|
14
|
+
cyan
|
15
|
+
gray
|
16
|
+
].freeze
|
17
|
+
|
18
|
+
COLORS.each.with_index do |color, index|
|
19
|
+
code = index + 30
|
20
|
+
define_method(color) do
|
21
|
+
"\e[#{code}m#{bleach}\e[0m"
|
22
|
+
end
|
23
|
+
bg_code = index + 40
|
24
|
+
define_method("bg_#{color}") do
|
25
|
+
"\e[#{bg_code}m#{bleach}\e[0m"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def initialize(str)
|
30
|
+
super(str.to_s)
|
31
|
+
end
|
32
|
+
|
33
|
+
def truncate(size)
|
34
|
+
if self.size > size
|
35
|
+
Text.new("#{self[..size]}...")
|
36
|
+
else
|
37
|
+
self
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def bleach
|
42
|
+
gsub(/\e\[\d{1,2}m/, "")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def Text(str) # rubocop:disable Naming/MethodName
|
47
|
+
Text.new(str)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ariadne
|
4
|
+
module Helpers
|
5
|
+
module ValueFormat
|
6
|
+
RUBY_LITERALS = [
|
7
|
+
NilClass,
|
8
|
+
String,
|
9
|
+
Integer,
|
10
|
+
Float,
|
11
|
+
Proc,
|
12
|
+
TrueClass,
|
13
|
+
FalseClass,
|
14
|
+
Symbol,
|
15
|
+
Array,
|
16
|
+
Range,
|
17
|
+
Regexp,
|
18
|
+
Hash
|
19
|
+
].freeze
|
20
|
+
|
21
|
+
def type(value)
|
22
|
+
return if value.is_a?(Class) || RUBY_LITERALS.include?(value.class)
|
23
|
+
|
24
|
+
value.class.name
|
25
|
+
end
|
26
|
+
|
27
|
+
def cast(value)
|
28
|
+
case value
|
29
|
+
when NilClass
|
30
|
+
"nil"
|
31
|
+
when Proc
|
32
|
+
"#<Proc>"
|
33
|
+
when Class
|
34
|
+
value.name
|
35
|
+
when String
|
36
|
+
"\"#{value}\""
|
37
|
+
else
|
38
|
+
value.to_s
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/ariadne/log.rb
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "open3"
|
4
|
-
require "ariadne/text"
|
4
|
+
require "ariadne/helpers/text"
|
5
|
+
require "ariadne/helpers/value_format"
|
5
6
|
|
6
7
|
module Ariadne
|
7
8
|
class Log
|
9
|
+
include Helpers::Text
|
10
|
+
include Helpers::ValueFormat
|
11
|
+
|
8
12
|
def initialize(seam)
|
9
13
|
@seam = seam
|
10
14
|
end
|
@@ -22,50 +26,54 @@ module Ariadne
|
|
22
26
|
|
23
27
|
def text
|
24
28
|
@text ||=
|
25
|
-
Text
|
26
|
-
[
|
27
|
-
|
28
|
-
|
29
|
-
|
29
|
+
Text(
|
30
|
+
[
|
31
|
+
rank,
|
32
|
+
" ",
|
33
|
+
depth_dashes,
|
34
|
+
class_name,
|
35
|
+
prefix,
|
36
|
+
method_name,
|
37
|
+
parameters,
|
38
|
+
return_value
|
39
|
+
].join
|
40
|
+
)
|
30
41
|
end
|
31
42
|
|
32
43
|
def rank
|
33
|
-
Text
|
34
|
-
end
|
35
|
-
|
36
|
-
def offset
|
37
|
-
Text.new("(#{@seam.offset})").gray
|
44
|
+
Text(@seam.rank.to_s.rjust(4)).gray
|
38
45
|
end
|
39
46
|
|
40
|
-
def
|
41
|
-
Text
|
47
|
+
def depth_dashes
|
48
|
+
Text("-" * @seam.depth).gray.tap { _1 << " " if @seam.depth.positive? }
|
42
49
|
end
|
43
50
|
|
44
51
|
def class_name
|
45
|
-
Text
|
52
|
+
Text(@seam.klass.name).green
|
46
53
|
end
|
47
54
|
|
48
55
|
def prefix
|
49
|
-
Text
|
56
|
+
Text(@seam.prefix).gray
|
50
57
|
end
|
51
58
|
|
52
59
|
def method_name
|
53
|
-
Text
|
60
|
+
Text(@seam.method_name).cyan
|
54
61
|
end
|
55
62
|
|
56
|
-
def
|
57
|
-
|
58
|
-
|
59
|
-
|
63
|
+
def return_value
|
64
|
+
value = Text(cast(@seam.return_value)).truncate(50)
|
65
|
+
value = type(@seam.return_value) ? "<#{type(@seam.return_value)}> #{value}" : value
|
66
|
+
Text(" -> #{value}").yellow
|
60
67
|
end
|
61
68
|
|
62
69
|
def parameters
|
63
|
-
|
70
|
+
str =
|
64
71
|
@seam.parameters.map do |parameter|
|
65
|
-
arg = Text
|
66
|
-
arg = parameter.
|
72
|
+
arg = Text(cast(parameter.arg)).truncate(50)
|
73
|
+
arg = type(parameter.arg) ? "<#{type(parameter.arg)}> #{arg}" : arg
|
67
74
|
"#{parameter.param}: #{arg}"
|
68
75
|
end.join(", ")
|
76
|
+
Text(str.empty? ? "" : "(#{str})").magenta
|
69
77
|
end
|
70
78
|
end
|
71
79
|
end
|
data/lib/ariadne/parameter.rb
CHANGED
@@ -1,25 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "open3"
|
4
|
-
require "ariadne/text"
|
5
4
|
|
6
5
|
module Ariadne
|
7
6
|
class Parameter < SimpleDelegator
|
8
|
-
RUBY_LITERALS = [
|
9
|
-
NilClass,
|
10
|
-
String,
|
11
|
-
Integer,
|
12
|
-
Float,
|
13
|
-
Proc,
|
14
|
-
TrueClass,
|
15
|
-
FalseClass,
|
16
|
-
Symbol,
|
17
|
-
Array,
|
18
|
-
Range,
|
19
|
-
Regexp,
|
20
|
-
Hash
|
21
|
-
].freeze
|
22
|
-
|
23
7
|
def initialize(parameter, binding:)
|
24
8
|
super(parameter)
|
25
9
|
@binding = binding
|
@@ -34,26 +18,5 @@ module Ariadne
|
|
34
18
|
rescue NameError
|
35
19
|
"?"
|
36
20
|
end
|
37
|
-
|
38
|
-
def type
|
39
|
-
return if arg.is_a?(Class) || RUBY_LITERALS.include?(arg.class)
|
40
|
-
|
41
|
-
arg.class.name
|
42
|
-
end
|
43
|
-
|
44
|
-
def stringified_arg
|
45
|
-
case arg
|
46
|
-
when NilClass
|
47
|
-
"nil"
|
48
|
-
when Proc
|
49
|
-
"#<Proc>"
|
50
|
-
when Class
|
51
|
-
arg.name
|
52
|
-
when String
|
53
|
-
"\"#{arg}\""
|
54
|
-
else
|
55
|
-
arg.to_s
|
56
|
-
end
|
57
|
-
end
|
58
21
|
end
|
59
22
|
end
|
data/lib/ariadne/seam.rb
CHANGED
@@ -4,37 +4,63 @@ require "open3"
|
|
4
4
|
require "ariadne/parameter"
|
5
5
|
|
6
6
|
module Ariadne
|
7
|
-
class Seam
|
8
|
-
attr_reader :rank, :
|
7
|
+
class Seam
|
8
|
+
attr_reader :rank, :depth, :klass, :method_name, :prefix, :parameters, :return_value, :binding, :path
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
class << self
|
11
|
+
# We cannot make public methods because accessing the TracePoint
|
12
|
+
# after it has been disabled would raise a RunTimeError
|
13
|
+
# with message "access from outside".
|
14
|
+
# We need to set the values while the TracePoint is enabled.
|
15
|
+
def build(tracepoint, rank:, depth:)
|
16
|
+
raise "tracepoint is disabled" unless tracepoint.enabled?
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
new(rank: rank, depth: depth).tap do |seam|
|
19
|
+
seam.instance_variable_set(:@klass, klass(tracepoint))
|
20
|
+
seam.instance_variable_set(:@prefix, prefix(tracepoint))
|
21
|
+
seam.instance_variable_set(:@method_name, method_name(tracepoint))
|
22
|
+
seam.instance_variable_set(:@parameters, parameters(tracepoint))
|
23
|
+
seam.instance_variable_set(:@path, path(tracepoint))
|
24
|
+
end
|
22
25
|
end
|
23
|
-
end
|
24
26
|
|
25
|
-
|
26
|
-
method_id
|
27
|
-
end
|
27
|
+
private
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
def klass(tracepoint)
|
30
|
+
if tracepoint.self.is_a?(Module)
|
31
|
+
tracepoint.self
|
32
|
+
else
|
33
|
+
tracepoint.self.class
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def method_name(tracepoint)
|
38
|
+
tracepoint.method_id
|
39
|
+
end
|
32
40
|
|
33
|
-
|
34
|
-
|
35
|
-
method.parameters.map do |parameter|
|
36
|
-
Parameter.new(parameter, binding: binding)
|
41
|
+
def prefix(tracepoint)
|
42
|
+
tracepoint.self.is_a?(Module) ? "." : "#"
|
37
43
|
end
|
44
|
+
|
45
|
+
def parameters(tracepoint)
|
46
|
+
method = tracepoint.self.method(tracepoint.method_id)
|
47
|
+
method.parameters.map do |parameter|
|
48
|
+
Parameter.new(parameter, binding: tracepoint.binding)
|
49
|
+
end
|
50
|
+
rescue NoMethodError
|
51
|
+
[]
|
52
|
+
end
|
53
|
+
|
54
|
+
def path(tracepoint)
|
55
|
+
tracepoint.path
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def initialize(rank:, depth:)
|
62
|
+
@rank = rank
|
63
|
+
@depth = depth
|
38
64
|
end
|
39
65
|
end
|
40
66
|
end
|
data/lib/ariadne/thread.rb
CHANGED
@@ -6,44 +6,86 @@ require "ariadne/log"
|
|
6
6
|
|
7
7
|
module Ariadne
|
8
8
|
class Thread
|
9
|
+
attr_reader :seams
|
10
|
+
|
9
11
|
LOG_FILE = "thread.log"
|
10
12
|
DEFAULT_INCLUDE_PATHS = Open3.capture3("pwd").first.strip
|
11
13
|
DEFAULT_EXCLUDE_PATHS = [].freeze
|
12
14
|
|
13
15
|
def initialize(include_paths: nil, exclude_paths: nil)
|
14
|
-
@include_paths = include_paths || DEFAULT_INCLUDE_PATHS
|
15
|
-
@exclude_paths = exclude_paths || DEFAULT_EXCLUDE_PATHS
|
16
|
+
@include_paths = Array(include_paths) || DEFAULT_INCLUDE_PATHS
|
17
|
+
@exclude_paths = Array(exclude_paths) || DEFAULT_EXCLUDE_PATHS
|
18
|
+
@seams = []
|
16
19
|
end
|
17
20
|
|
18
21
|
def call
|
19
|
-
|
20
|
-
|
21
|
-
file = File.open(LOG_FILE, "w")
|
22
|
-
trace = build_trace
|
22
|
+
prepare
|
23
|
+
open_file
|
23
24
|
trace.enable
|
24
25
|
yield
|
25
26
|
ensure
|
26
27
|
trace.disable
|
27
|
-
|
28
|
+
log
|
29
|
+
close_file
|
28
30
|
end
|
29
31
|
|
30
32
|
private
|
31
33
|
|
32
|
-
def
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
34
|
+
def prepare
|
35
|
+
@rank = 0
|
36
|
+
@depth = 0
|
37
|
+
@seams = []
|
38
|
+
end
|
39
|
+
|
40
|
+
def open_file
|
41
|
+
@file = File.open(LOG_FILE, "w")
|
42
|
+
end
|
43
|
+
|
44
|
+
def close_file
|
45
|
+
@file.close
|
46
|
+
end
|
47
|
+
|
48
|
+
def trace
|
49
|
+
@trace ||=
|
50
|
+
TracePoint.new(:call, :return) do |tracepoint|
|
51
|
+
next if tracepoint.self.is_a?(TracePoint)
|
52
|
+
|
53
|
+
case tracepoint.event
|
54
|
+
when :call
|
55
|
+
on_call(tracepoint)
|
56
|
+
when :return
|
57
|
+
on_return(tracepoint)
|
58
|
+
end
|
45
59
|
end
|
46
|
-
|
60
|
+
end
|
61
|
+
|
62
|
+
def on_call(tracepoint)
|
63
|
+
return unless selected?(tracepoint)
|
64
|
+
|
65
|
+
seam = Seam.build(tracepoint, rank: @rank, depth: @depth)
|
66
|
+
@seams << seam
|
67
|
+
|
68
|
+
@rank += 1
|
69
|
+
@depth += 1
|
70
|
+
end
|
71
|
+
|
72
|
+
def on_return(tracepoint)
|
73
|
+
return unless selected?(tracepoint)
|
74
|
+
|
75
|
+
@depth -= 1
|
76
|
+
|
77
|
+
seam = @seams.reverse.find { _1.depth == @depth }
|
78
|
+
seam&.instance_variable_set(:@return_value, tracepoint.return_value)
|
79
|
+
seam&.instance_variable_set(:@binding, tracepoint.binding)
|
80
|
+
end
|
81
|
+
|
82
|
+
def selected?(tracepoint)
|
83
|
+
@include_paths.any? { tracepoint.path.include?(_1) } &&
|
84
|
+
@exclude_paths.none? { tracepoint.path.include?(_1) }
|
85
|
+
end
|
86
|
+
|
87
|
+
def log
|
88
|
+
@seams.each { Log.new(_1).call }
|
47
89
|
end
|
48
90
|
end
|
49
91
|
end
|
data/lib/ariadne/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ariadne
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edouard Piron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-02-
|
11
|
+
date: 2023-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -80,20 +80,6 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: simplecov
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: yard
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -116,10 +102,11 @@ extensions: []
|
|
116
102
|
extra_rdoc_files: []
|
117
103
|
files:
|
118
104
|
- lib/ariadne.rb
|
105
|
+
- lib/ariadne/helpers/text.rb
|
106
|
+
- lib/ariadne/helpers/value_format.rb
|
119
107
|
- lib/ariadne/log.rb
|
120
108
|
- lib/ariadne/parameter.rb
|
121
109
|
- lib/ariadne/seam.rb
|
122
|
-
- lib/ariadne/text.rb
|
123
110
|
- lib/ariadne/thread.rb
|
124
111
|
- lib/ariadne/version.rb
|
125
112
|
homepage: https://github.com/BigBigDoudou/ariadne
|
data/lib/ariadne/text.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Ariadne
|
4
|
-
class Text < String
|
5
|
-
COLORS = %w[
|
6
|
-
black
|
7
|
-
red
|
8
|
-
green
|
9
|
-
yellow
|
10
|
-
blue
|
11
|
-
magenta
|
12
|
-
cyan
|
13
|
-
gray
|
14
|
-
].freeze
|
15
|
-
|
16
|
-
COLORS.each.with_index do |color, index|
|
17
|
-
code = index + 30
|
18
|
-
define_method(color) do
|
19
|
-
"\e[#{code}m#{bleach}\e[0m"
|
20
|
-
end
|
21
|
-
bg_code = index + 40
|
22
|
-
define_method("bg_#{color}") do
|
23
|
-
"\e[#{bg_code}m#{bleach}\e[0m"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def initialize(str)
|
28
|
-
super(str.to_s)
|
29
|
-
end
|
30
|
-
|
31
|
-
def truncate(size)
|
32
|
-
if self.size > size
|
33
|
-
Text.new("#{self[..size]}...")
|
34
|
-
else
|
35
|
-
self
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def bleach
|
40
|
-
gsub(/\e\[\d{1,2}m/, "")
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|