ariadne 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4d6969e929cebeb85281888cf5be5ba9b2460345d217e1572b32888f13eb6d06
4
+ data.tar.gz: bee2a2b5bd7b8160af83b79f4a1197370edcba60096c395730dfd28428887acf
5
+ SHA512:
6
+ metadata.gz: 7512bf90d2dde907c79a2aa7fbb6d52f751062ecb2851a52c8a921159e43e5ee2044746630d404b7c22946065a81e86b4d3006a529c40ad3ca3d107d1be3ff6a
7
+ data.tar.gz: 40dcdd1799bf14bdd3873a2d50206fb97ada9e0585ace1d9dc5ab1ca6e3ac37d9f8a700d08179f53474de61e9a6c4bd01882f3ee27c798f53ce14bde0b0bbf05
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "open3"
4
+ require "ariadne/text"
5
+
6
+ module Ariadne
7
+ class Log
8
+ def initialize(seam)
9
+ @seam = seam
10
+ end
11
+
12
+ def call
13
+ puts(
14
+ Text.new(
15
+ [rank, " ", offset, " ", offset_dashes, class_name, prefix, method_name]
16
+ .tap { add_parameters(_1) }
17
+ .join
18
+ ).truncate(200)
19
+ )
20
+ end
21
+
22
+ private
23
+
24
+ def rank
25
+ Text.new(@seam.rank.to_s.rjust(4)).gray
26
+ end
27
+
28
+ def offset
29
+ Text.new("(#{@seam.offset})").gray
30
+ end
31
+
32
+ def offset_dashes
33
+ Text.new("-" * @seam.offset).gray.tap { _1 << " " if @seam.offset.positive? }
34
+ end
35
+
36
+ def class_name
37
+ Text.new(@seam.class_name).green
38
+ end
39
+
40
+ def prefix
41
+ Text.new(@seam.prefix).gray
42
+ end
43
+
44
+ def method_name
45
+ Text.new(@seam.method_name).cyan
46
+ end
47
+
48
+ def add_parameters(str)
49
+ return if parameters == ""
50
+
51
+ str << Text.new("(#{parameters})").magenta
52
+ end
53
+
54
+ def parameters
55
+ @parameters ||=
56
+ @seam.parameters.map do |parameter|
57
+ arg = Text.new(parameter.stringified_arg).truncate(50)
58
+ arg = parameter.type ? "<#{parameter.type}> #{arg}" : arg
59
+ "#{parameter.param}: #{arg}"
60
+ end.join(", ")
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "open3"
4
+ require "ariadne/text"
5
+
6
+ module Ariadne
7
+ 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
+ def initialize(parameter, binding:)
24
+ super(parameter)
25
+ @binding = binding
26
+ end
27
+
28
+ def param
29
+ last
30
+ end
31
+
32
+ def arg
33
+ @binding.local_variable_get(last)
34
+ rescue NameError
35
+ "?"
36
+ 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
+ end
59
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "open3"
4
+ require "ariadne/parameter"
5
+
6
+ module Ariadne
7
+ class Seam < SimpleDelegator
8
+ attr_reader :rank, :offset
9
+
10
+ def initialize(tracepoint, rank:, offset:)
11
+ super(tracepoint)
12
+ @rank = rank
13
+ @offset = offset
14
+ end
15
+
16
+ # Seam.new(@rank, class_name(tp), prefix(tp), tp.method_id, parameters, @seams.size)
17
+ def class_name
18
+ __getobj__.self.is_a?(Class) ? __getobj__.self.name : __getobj__.self.class.name
19
+ end
20
+
21
+ def method_name
22
+ method_id
23
+ end
24
+
25
+ def prefix
26
+ __getobj__.self.is_a?(Class) ? "." : "#"
27
+ end
28
+
29
+ def parameters
30
+ method = __getobj__.self.method(method_name)
31
+ method.parameters.map do |parameter|
32
+ Parameter.new(parameter, binding: binding)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,39 @@
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#{self}\e[0m"
20
+ end
21
+ bg_code = index + 40
22
+ define_method("bg_#{color}") do
23
+ "\e[#{bg_code}m#{self}\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
+ self[..size]
34
+ else
35
+ self
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "open3"
4
+ require "ariadne/seam"
5
+ require "ariadne/log"
6
+
7
+ module Ariadne
8
+ class Thread
9
+ DEFAULT_INCLUDE_PATHS = Open3.capture3("pwd").first.strip
10
+ DEFAULT_EXCLUDE_PATHS = [].freeze
11
+
12
+ def initialize(include_paths: nil, exclude_paths: nil)
13
+ @include_paths = include_paths || DEFAULT_INCLUDE_PATHS
14
+ @exclude_paths = exclude_paths || DEFAULT_EXCLUDE_PATHS
15
+ @seams = []
16
+ @rank = 0
17
+ end
18
+
19
+ def call
20
+ trace = build_trace
21
+ trace.enable
22
+ yield
23
+ ensure
24
+ trace.disable
25
+ end
26
+
27
+ private
28
+
29
+ def build_trace
30
+ TracePoint.new(:call, :return) do |tp|
31
+ next if @include_paths.none? { tp.path.include?(_1) }
32
+ next if @exclude_paths.any? { tp.path.include?(_1) }
33
+
34
+ case tp.event
35
+ when :call
36
+ seam = Seam.new(tp, rank: @rank, offset: @seams.size)
37
+ @seams << seam
38
+ @rank += 1
39
+ Log.new(seam).call
40
+ when :return
41
+ @seams.pop
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ariadne
4
+ VERSION = "0.0.1"
5
+ end
data/lib/ariadne.rb ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ariadne/version"
4
+
5
+ # Entrypoint
6
+ module Ariadne; end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ariadne
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Edouard Piron
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-02-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
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
+ - !ruby/object:Gem::Dependency
98
+ name: yard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Follow the code
112
+ email:
113
+ - ed.piron@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - lib/ariadne.rb
119
+ - lib/ariadne/log.rb
120
+ - lib/ariadne/parameter.rb
121
+ - lib/ariadne/seam.rb
122
+ - lib/ariadne/text.rb
123
+ - lib/ariadne/thread.rb
124
+ - lib/ariadne/version.rb
125
+ homepage: https://github.com/BigBigDoudou/ariadne
126
+ licenses:
127
+ - MIT
128
+ metadata:
129
+ homepage_uri: https://github.com/BigBigDoudou/ariadne
130
+ source_code_uri: https://github.com/perangusta/ariadne
131
+ changelog_uri: https://github.com/perangusta/ariadne/CHANGELOG.md
132
+ rubygems_mfa_required: 'true'
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '3.0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubygems_version: 3.2.32
149
+ signing_key:
150
+ specification_version: 4
151
+ summary: Follow the code
152
+ test_files: []