trace_eval 0.1.1 → 0.1.5
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 +1 -3
- data/README.md +69 -7
- data/lib/trace_eval/version.rb +1 -1
- data/lib/trace_eval.rb +1 -4
- data/trace_eval.gemspec +1 -3
- metadata +4 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b32d9cc35ebe136968c891eb8806e579c88116301f8f2e74dbce59847de2fe04
|
4
|
+
data.tar.gz: effd109d975752c4428acefee763830916b9d7fe1e4bd96f80c409f454ece571
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98aedb41439c4221bb0aa7611d0411cbbf62aa106632d1cfa1adfcf771113bcdd86aeab528832a355191fc8f686631c45378ac377e9de5129d6f104695983aaa
|
7
|
+
data.tar.gz: 4093cfda441ddf9fbeade79f0c9035bc3f4112cbe3f8c0ffb69c4a9bc3c9f5feaae3e56b99003d09b78ce263cd82d5358e1eaba308d3ff69502584a420ce4283
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,21 @@
|
|
1
1
|
# TraceEval
|
2
2
|
|
3
|
-
|
4
|
-
need to be able to package up your Ruby library into a gem. Put your
|
5
|
-
Ruby code in the file `lib/trace_eval`. To experiment with that code,
|
6
|
-
run `bin/console` for an interactive prompt.
|
3
|
+
Evaluates the Ruby expression(s) in string and prints each executing line.
|
7
4
|
|
8
|
-
|
5
|
+
The standard ruby `tracer` does not display the source inside an `eval`:
|
6
|
+
|
7
|
+
```
|
8
|
+
$ ruby -rtracer foo.rb
|
9
|
+
#0:foo.rb:1::-: puts 1+2
|
10
|
+
3
|
11
|
+
#0:foo.rb:2::-: eval "puts 3+4\nputs 5+6\n"
|
12
|
+
#0:(eval):1::-: -
|
13
|
+
7
|
14
|
+
#0:(eval):2::-: -
|
15
|
+
11
|
16
|
+
#0:foo.rb:3::-: puts 7+8
|
17
|
+
15
|
18
|
+
```
|
9
19
|
|
10
20
|
## Installation
|
11
21
|
|
@@ -25,7 +35,58 @@ Or install it yourself as:
|
|
25
35
|
|
26
36
|
## Usage
|
27
37
|
|
28
|
-
|
38
|
+
```
|
39
|
+
$ ./bin/console
|
40
|
+
irb(main):001:0> extend TraceEval
|
41
|
+
=> main
|
42
|
+
irb(main):002:0> trace_eval "a = 2\nb = 2\nputs a+b\n"
|
43
|
+
a = 2
|
44
|
+
b = 2
|
45
|
+
puts a+b
|
46
|
+
4
|
47
|
+
=> nil
|
48
|
+
```
|
49
|
+
|
50
|
+
### Bugs
|
51
|
+
|
52
|
+
If the traced eval in turn evals, the trace will be nonsense:
|
53
|
+
|
54
|
+
```
|
55
|
+
irb(main):001:0> extend TraceEval
|
56
|
+
=> main
|
57
|
+
irb(main):002:0> trace_eval "0+1\neval \"2+3\n4+5\n\"\n6+7\n"
|
58
|
+
0+1
|
59
|
+
eval "2+3
|
60
|
+
0+1
|
61
|
+
eval "2+3
|
62
|
+
6+7
|
63
|
+
=> 13
|
64
|
+
```
|
65
|
+
|
66
|
+
Nested `trace_eval` does work:
|
67
|
+
|
68
|
+
```
|
69
|
+
irb(main):001:0> extend TraceEval
|
70
|
+
=> main
|
71
|
+
irb(main):002:0> trace_eval "0+1\ntrace_eval \"2+3\n4+5\n\"\n6+7\n"
|
72
|
+
0+1
|
73
|
+
trace_eval "2+3
|
74
|
+
2+3
|
75
|
+
4+5
|
76
|
+
6+7
|
77
|
+
=> 13
|
78
|
+
```
|
79
|
+
|
80
|
+
## Concept of Operation
|
81
|
+
|
82
|
+
- Save a random value in a magic variable to distinguish this eval
|
83
|
+
from others
|
84
|
+
- Save an array of the lines of the eval string
|
85
|
+
- Set a `TracePoint` for `:line` events (execute code on a new line)
|
86
|
+
- When the trace point is activated
|
87
|
+
- Only proceed if the line's `path` is '(eval)'
|
88
|
+
- Only proceed if the magic variable matches the expected value
|
89
|
+
- Print the appropriate line from the array by `lineno`
|
29
90
|
|
30
91
|
## Development
|
31
92
|
|
@@ -41,7 +102,8 @@ push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
41
102
|
|
42
103
|
## Contributing
|
43
104
|
|
44
|
-
Bug reports and pull requests are welcome on
|
105
|
+
Bug reports and pull requests are welcome on GitLab at
|
106
|
+
https://gitlab.com/fjc/trace_eval.
|
45
107
|
|
46
108
|
## License
|
47
109
|
|
data/lib/trace_eval/version.rb
CHANGED
data/lib/trace_eval.rb
CHANGED
@@ -14,15 +14,12 @@ module TraceEval
|
|
14
14
|
] + code.lines
|
15
15
|
|
16
16
|
tp = TracePoint.new(:line) do |tp|
|
17
|
-
tp.disable
|
18
17
|
next unless tp.path == '(eval)'
|
19
18
|
next unless tp.binding.local_variable_get(
|
20
19
|
:__wzpxmnrjafemvlrwflblbbyenywk__
|
21
20
|
)==__wzpxmnrjafemvlrwflblbbyenywk__
|
22
|
-
print lines[tp.lineno]
|
21
|
+
$stderr.print lines[tp.lineno]
|
23
22
|
rescue NameError
|
24
|
-
ensure
|
25
|
-
tp.enable
|
26
23
|
end
|
27
24
|
|
28
25
|
begin
|
data/trace_eval.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.authors = ['Frank J. Cameron']
|
9
9
|
spec.email = ['fjc@fastmail.net']
|
10
10
|
|
11
|
-
spec.summary = ''
|
11
|
+
spec.summary = 'Evaluates the Ruby expression(s) in string and prints each executing line.'
|
12
12
|
spec.homepage = 'https://gitlab.com/fjc/trace_eval'
|
13
13
|
spec.license = 'MIT'
|
14
14
|
spec.required_ruby_version = '>= 2.7.0'
|
@@ -26,6 +26,4 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.bindir = 'exe'
|
27
27
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
28
28
|
spec.require_paths = ['lib']
|
29
|
-
|
30
|
-
spec.add_dependency 'chunky_png'
|
31
29
|
end
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trace_eval
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frank J. Cameron
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-11-
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: chunky_png
|
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'
|
11
|
+
date: 2021-11-08 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
27
13
|
description:
|
28
14
|
email:
|
29
15
|
- fjc@fastmail.net
|
@@ -66,5 +52,5 @@ requirements: []
|
|
66
52
|
rubygems_version: 3.1.6
|
67
53
|
signing_key:
|
68
54
|
specification_version: 4
|
69
|
-
summary:
|
55
|
+
summary: Evaluates the Ruby expression(s) in string and prints each executing line.
|
70
56
|
test_files: []
|