trace_eval 0.1.4 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7f6ff5fef886f2d284b9bc0b9dae8e4dd33a8bf1591b8a014881332191098b9
4
- data.tar.gz: 703b600f8c29f3a28e5942cfea74ed7e7fac3882b0d9b7982b730f3d902bb5ab
3
+ metadata.gz: b32d9cc35ebe136968c891eb8806e579c88116301f8f2e74dbce59847de2fe04
4
+ data.tar.gz: effd109d975752c4428acefee763830916b9d7fe1e4bd96f80c409f454ece571
5
5
  SHA512:
6
- metadata.gz: cb4ceec4235ac214b863eed73a26c20cc98a58c43293acc319dd9f0f798828c43e3ab68152e04a6d6a74b48db79da322c78ef1d8f8f2cc5b410a11b5dcb01378
7
- data.tar.gz: 8a125143366cf66aed24f2cc35768ddbee74cce5fec467a3a05290335a39a9395ec52c24e34e055a273765efda41614736e7809648fd166c59002a6682184e45
6
+ metadata.gz: 98aedb41439c4221bb0aa7611d0411cbbf62aa106632d1cfa1adfcf771113bcdd86aeab528832a355191fc8f686631c45378ac377e9de5129d6f104695983aaa
7
+ data.tar.gz: 4093cfda441ddf9fbeade79f0c9035bc3f4112cbe3f8c0ffb69c4a9bc3c9f5feaae3e56b99003d09b78ce263cd82d5358e1eaba308d3ff69502584a420ce4283
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- trace_eval (0.1.4)
4
+ trace_eval (0.1.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -2,6 +2,21 @@
2
2
 
3
3
  Evaluates the Ruby expression(s) in string and prints each executing line.
4
4
 
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
+ ```
19
+
5
20
  ## Installation
6
21
 
7
22
  Add this line to your application's Gemfile:
@@ -32,6 +47,47 @@ puts a+b
32
47
  => nil
33
48
  ```
34
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`
90
+
35
91
  ## Development
36
92
 
37
93
  After checking out the repo, run `bin/setup` to install
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TraceEval
4
- VERSION = '0.1.4'
4
+ VERSION = '0.1.5'
5
5
  end
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
21
  $stderr.print lines[tp.lineno]
23
22
  rescue NameError
24
- ensure
25
- tp.enable
26
23
  end
27
24
 
28
25
  begin
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trace_eval
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
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-02 00:00:00.000000000 Z
11
+ date: 2021-11-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: