qed 3.0.0 → 3.0.2
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/HISTORY.md +22 -0
- data/demo/14_comment_mode.md +26 -0
- data/demo/15_working_directory.md +41 -0
- data/demo/samples/yard.rb +19 -0
- data/lib/qed/cli/qed.rb +1 -1
- data/lib/qed/evaluator.rb +10 -2
- data/lib/qed/parser.rb +31 -1
- data/lib/qed/scope.rb +21 -15
- data/lib/qed/version.rb +1 -1
- metadata +4 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1e859a8b406be860b774e565210d752764d661c8f699a8877a15697f206e413a
|
|
4
|
+
data.tar.gz: 23633b17dffb15a02824df4d64900f2c20cda6212f211cffe81fb72eaa2983a0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c612dfba89c214c1fc2bed469f43da2d2a2ec5d85a94c16973f1e6706f2467db49955f4cda4d61443b2be0f2114a62a0bc876df99c94f38b373c1157302510a7
|
|
7
|
+
data.tar.gz: 3883aed91cb2ff8b5a69d4837184a348d06b954bebd7d6f15689b9cea105249315a81426b49b297c90137836cc4a072b10c8b4990567335e2cd457c1ec5be2e4
|
data/HISTORY.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# RELEASE HISTORY
|
|
2
2
|
|
|
3
|
+
## 3.0.2 | 2026-11-29
|
|
4
|
+
|
|
5
|
+
Bug Fixes:
|
|
6
|
+
|
|
7
|
+
* The `clear_working_directory!` helper works again. It raised a TypeError
|
|
8
|
+
("no implicit conversion of nil into String"), as the directory it was
|
|
9
|
+
to clear was never set. It now clears the temporary directory the
|
|
10
|
+
demonstrations are run in, hidden files included, and raises an error
|
|
11
|
+
if they are being run from the project's root (`--rooted`), where there
|
|
12
|
+
is no temporary directory.
|
|
13
|
+
|
|
14
|
+
## 3.0.1 | 2026-11-13
|
|
15
|
+
|
|
16
|
+
Bug Fixes:
|
|
17
|
+
|
|
18
|
+
* In comment mode (`--comment`), the indented lines that continue a YARD
|
|
19
|
+
tag, such as the second line of a `@deprecated` or `@return`, are now
|
|
20
|
+
read as the tag's text instead of being run as example code. The code
|
|
21
|
+
under an `@example` tag still runs.
|
|
22
|
+
* Each `-I` option now adds to the load path. Before, only the last one
|
|
23
|
+
took effect, so `-Ilib/core -Ilib/standard` lost `lib/core`.
|
|
24
|
+
|
|
3
25
|
## 3.0.0 | 2026-03-31
|
|
4
26
|
|
|
5
27
|
Major modernization release after a long hiatus.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Comment Mode
|
|
2
|
+
|
|
3
|
+
With the `--comment` option, QED runs the examples in the comments of
|
|
4
|
+
a Ruby script, the indented lines, as it would a demo's.
|
|
5
|
+
|
|
6
|
+
sample = File.dirname(__FILE__) + '/samples/yard.rb'
|
|
7
|
+
demo = QED::Demo.new(sample, :mode=>:comment)
|
|
8
|
+
code = demo.steps.select(&:code?).map { |step| step.code.strip }
|
|
9
|
+
|
|
10
|
+
A plain example runs, and so does the code under an `@example` tag.
|
|
11
|
+
|
|
12
|
+
code.assert.include?("YardSample.double(2).must_return(4)")
|
|
13
|
+
code.assert.include?("YardSample.double(1.5).must_return(3.0)")
|
|
14
|
+
|
|
15
|
+
## YARD Tags
|
|
16
|
+
|
|
17
|
+
YARD continues a tag's text on the indented lines after it. Those
|
|
18
|
+
lines are part of the tag, not example code, so they don't run.
|
|
19
|
+
|
|
20
|
+
code.grep(/Scheduled/).assert.empty?
|
|
21
|
+
code.grep(/times two/).assert.empty?
|
|
22
|
+
|
|
23
|
+
The tag's text is kept with the explanation instead.
|
|
24
|
+
|
|
25
|
+
text = demo.steps.map(&:explain).join
|
|
26
|
+
text.assert.include?("Scheduled for removal next year.")
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Working Directory
|
|
2
|
+
|
|
3
|
+
Demonstrations are run in a temporary directory, `tmp/qed` in the project,
|
|
4
|
+
so that the files they make are kept out of the way.
|
|
5
|
+
|
|
6
|
+
File.basename(Dir.pwd).assert == 'qed'
|
|
7
|
+
|
|
8
|
+
Let's make a few files there, one of them hidden and one in a directory
|
|
9
|
+
of its own.
|
|
10
|
+
|
|
11
|
+
require 'fileutils'
|
|
12
|
+
|
|
13
|
+
File.write('example.txt', 'An example.')
|
|
14
|
+
File.write('.hidden', 'Hidden.')
|
|
15
|
+
|
|
16
|
+
FileUtils.mkdir_p('sub/dir')
|
|
17
|
+
File.write('sub/dir/deep.txt', 'Deep.')
|
|
18
|
+
|
|
19
|
+
The directory is cleared before a session starts. To clear it at other
|
|
20
|
+
times, say before each demonstration, there is the `clear_working_directory!`
|
|
21
|
+
helper.
|
|
22
|
+
|
|
23
|
+
clear_working_directory!
|
|
24
|
+
|
|
25
|
+
Everything in it is gone,
|
|
26
|
+
|
|
27
|
+
Dir.children('.').assert == []
|
|
28
|
+
|
|
29
|
+
and the directory itself remains, with us still in it.
|
|
30
|
+
|
|
31
|
+
File.assert.directory?(Dir.pwd)
|
|
32
|
+
|
|
33
|
+
It is usually called from an applique file, like so:
|
|
34
|
+
|
|
35
|
+
Before :demo do
|
|
36
|
+
clear_working_directory!
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
When demonstrations are run from the project's root instead, with the
|
|
40
|
+
`--rooted` option, there is no temporary directory, and the helper raises
|
|
41
|
+
an error in place of clearing the project.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module YardSample
|
|
2
|
+
|
|
3
|
+
# Doubles a number.
|
|
4
|
+
#
|
|
5
|
+
# YardSample.double(2) #=> 4
|
|
6
|
+
#
|
|
7
|
+
# @deprecated Use #twice instead.
|
|
8
|
+
# Scheduled for removal next year.
|
|
9
|
+
#
|
|
10
|
+
# @example Doubling a float
|
|
11
|
+
# YardSample.double(1.5) #=> 3.0
|
|
12
|
+
#
|
|
13
|
+
# @return [Numeric] The number,
|
|
14
|
+
# times two.
|
|
15
|
+
def self.double(n)
|
|
16
|
+
n * 2
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
data/lib/qed/cli/qed.rb
CHANGED
|
@@ -105,7 +105,7 @@ module QED
|
|
|
105
105
|
options[:mode] = :comment
|
|
106
106
|
end
|
|
107
107
|
opt.on('--loadpath', "-I PATH", "add paths to $LOAD_PATH") do |paths|
|
|
108
|
-
options[:loadpath] = paths.split(/[:;]/).map{|d| File.expand_path(d)}
|
|
108
|
+
options[:loadpath] = (options[:loadpath] || []) + paths.split(/[:;]/).map{|d| File.expand_path(d)}
|
|
109
109
|
end
|
|
110
110
|
opt.on('--require', "-r LIB", "require feature (immediately)") do |paths|
|
|
111
111
|
requires = paths.split(/[:;]/)
|
data/lib/qed/evaluator.rb
CHANGED
|
@@ -27,13 +27,21 @@ module QED
|
|
|
27
27
|
@demo = demo
|
|
28
28
|
@steps = demo.steps
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
@settings = options[:settings]
|
|
31
31
|
@applique = options[:applique] # BOOLEAN FLAG
|
|
32
32
|
|
|
33
33
|
@observers = options[:observers].to_a
|
|
34
34
|
@observers += applique_observers
|
|
35
35
|
|
|
36
|
-
@scope = options[:scope] || Scope.new(demo)
|
|
36
|
+
@scope = options[:scope] || Scope.new(demo, :tmpdir=>temporary_directory)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# The temporary directory the demos are run in, or nil when they are
|
|
40
|
+
# run from the project's root (--rooted) or outside of a session.
|
|
41
|
+
def temporary_directory
|
|
42
|
+
return nil unless @settings
|
|
43
|
+
return nil if @settings.rooted
|
|
44
|
+
@settings.tmpdir
|
|
37
45
|
end
|
|
38
46
|
|
|
39
47
|
# Collect applique all the signal-based advice and wrap their evaluation
|
data/lib/qed/parser.rb
CHANGED
|
@@ -62,10 +62,15 @@ module QED
|
|
|
62
62
|
# TODO: It would be nice if we could get ther require statement for the
|
|
63
63
|
# comment mode to be relative to an actual loadpath.
|
|
64
64
|
|
|
65
|
+
# A YARD tag or directive at the start of a comment, as in
|
|
66
|
+
# `# @deprecated Use #bar instead.`
|
|
67
|
+
YARD_TAG = /\A@!?((?:\w\.?)+)/
|
|
68
|
+
|
|
65
69
|
# Parse comment lines into a format that the parse method can use.
|
|
66
70
|
def parse_comment_lines
|
|
67
71
|
ruby_omit = false
|
|
68
72
|
rdoc_omit = false
|
|
73
|
+
yard_tag = nil
|
|
69
74
|
lines = [
|
|
70
75
|
[0, "Load #{File.basename(file)} script.\n"],
|
|
71
76
|
[0, "\n"],
|
|
@@ -87,8 +92,12 @@ module QED
|
|
|
87
92
|
when /^\s*##/
|
|
88
93
|
## skip internal comments
|
|
89
94
|
when /^\s*\#/
|
|
90
|
-
|
|
95
|
+
unless (ruby_omit or rdoc_omit)
|
|
96
|
+
text, yard_tag = yard_comment(l.lstrip.sub(/^\#\ ?/, ''), yard_tag)
|
|
97
|
+
lines << [index, text]
|
|
98
|
+
end
|
|
91
99
|
else
|
|
100
|
+
yard_tag = nil
|
|
92
101
|
lines << [index, "\n"] unless lines.last[1] == "\n" unless (ruby_omit or rdoc_omit)
|
|
93
102
|
end
|
|
94
103
|
index += 1
|
|
@@ -96,6 +105,27 @@ module QED
|
|
|
96
105
|
lines
|
|
97
106
|
end
|
|
98
107
|
|
|
108
|
+
# YARD continues a tag's text on the indented lines after it, across
|
|
109
|
+
# blank lines, until a line that is not indented. Those lines are part
|
|
110
|
+
# of the tag, not example code, so they are passed on unindented. The
|
|
111
|
+
# exception is `@example`, whose lines are code.
|
|
112
|
+
#
|
|
113
|
+
# @return [Array(String, String)] The comment text, and the name of the
|
|
114
|
+
# tag it belongs to, if any.
|
|
115
|
+
def yard_comment(text, tag)
|
|
116
|
+
if md = YARD_TAG.match(text)
|
|
117
|
+
[text, md[1]]
|
|
118
|
+
elsif tag.nil? || text.strip.empty?
|
|
119
|
+
[text, tag]
|
|
120
|
+
elsif !text.start_with?(' ', "\t")
|
|
121
|
+
[text, nil]
|
|
122
|
+
elsif tag == 'example'
|
|
123
|
+
[text, tag]
|
|
124
|
+
else
|
|
125
|
+
[text.lstrip, tag]
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
99
129
|
# Parse demo file into steps.
|
|
100
130
|
def parse
|
|
101
131
|
steps = []
|
data/lib/qed/scope.rb
CHANGED
|
@@ -16,7 +16,7 @@ module QED
|
|
|
16
16
|
@_applique = demo.applique_prime
|
|
17
17
|
|
|
18
18
|
@_file = demo.file
|
|
19
|
-
@
|
|
19
|
+
@_tmpdir = options[:tmpdir]
|
|
20
20
|
|
|
21
21
|
@_features = []
|
|
22
22
|
|
|
@@ -164,29 +164,35 @@ module QED
|
|
|
164
164
|
end
|
|
165
165
|
end
|
|
166
166
|
|
|
167
|
-
# Helper method to clear temporary work directory
|
|
167
|
+
# Helper method to clear the temporary work directory, the one the
|
|
168
|
+
# demos are run in (usually `tmp/qed` in the project). Everything in
|
|
169
|
+
# it is removed, hidden files included; the directory itself stays.
|
|
170
|
+
#
|
|
171
|
+
# It is an error to call it when the demos are not being run in a
|
|
172
|
+
# temporary directory, as with the `--rooted` option, since the
|
|
173
|
+
# directory cleared would then be the project itself.
|
|
168
174
|
#
|
|
169
175
|
def clear_working_directory!
|
|
170
|
-
|
|
171
|
-
|
|
176
|
+
unless @_tmpdir
|
|
177
|
+
raise "No temporary directory to clear: " \
|
|
178
|
+
"the demos are being run from the project's root."
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
dir = File.expand_path(@_tmpdir)
|
|
172
182
|
|
|
173
|
-
if dir == '/' or dir == File.expand_path('~')
|
|
174
|
-
abort "DANGER! Trying to use home or
|
|
183
|
+
if dir == '/' or dir == File.expand_path('~') or dir == File.expand_path(Utils.root)
|
|
184
|
+
abort "DANGER! Trying to use home, root or the project as a temporary directory!"
|
|
175
185
|
end
|
|
176
186
|
|
|
177
|
-
|
|
187
|
+
return unless File.directory?(dir)
|
|
178
188
|
|
|
179
|
-
|
|
189
|
+
require 'fileutils'
|
|
180
190
|
|
|
181
|
-
|
|
182
|
-
|
|
191
|
+
Dir.children(dir).each do |entry|
|
|
192
|
+
FileUtils.rm_rf(File.join(dir, entry))
|
|
193
|
+
end
|
|
183
194
|
end
|
|
184
195
|
|
|
185
|
-
# TODO: Project's root directory.
|
|
186
|
-
#def rootdir
|
|
187
|
-
# @_root
|
|
188
|
-
#end
|
|
189
|
-
|
|
190
196
|
# Redirect constant missing to toplevel (i.e. Object). This is
|
|
191
197
|
# to allow the evaluation scope to emulate the toplevel.
|
|
192
198
|
def const_missing(const)
|
data/lib/qed/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: qed
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.0.
|
|
4
|
+
version: 3.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- trans
|
|
@@ -92,6 +92,8 @@ files:
|
|
|
92
92
|
- demo/10_constant_lookup.md
|
|
93
93
|
- demo/11_embedded_rules.md
|
|
94
94
|
- demo/13_fenced_code_blocks.md
|
|
95
|
+
- demo/14_comment_mode.md
|
|
96
|
+
- demo/15_working_directory.md
|
|
95
97
|
- demo/99_issues/02_topcode.md
|
|
96
98
|
- demo/applique/ae.rb
|
|
97
99
|
- demo/applique/constant.rb
|
|
@@ -104,6 +106,7 @@ files:
|
|
|
104
106
|
- demo/helpers/toplevel.rb
|
|
105
107
|
- demo/samples/data.txt
|
|
106
108
|
- demo/samples/table.yml
|
|
109
|
+
- demo/samples/yard.rb
|
|
107
110
|
- lib/qed.rb
|
|
108
111
|
- lib/qed/applique.rb
|
|
109
112
|
- lib/qed/cli.rb
|