rundoc 4.1.0 → 4.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8ca738c51da79babb0fba6093b9d2055e6efd6d435d56b3397aed926d002701d
4
- data.tar.gz: be7e9bd2c06a3a0e92dd078a3cd66d67f77b7cf1f4490190281fb7e573f8696e
3
+ metadata.gz: 175e8af5e0beeb7acca8d32740f3379d68771ba207d723a1f51495848645249c
4
+ data.tar.gz: ac404b2c8337948628d7f18b90b20c57668f8a059d6e10c9c64354d21e04ac58
5
5
  SHA512:
6
- metadata.gz: 7db578e4f26a9b347ca93d8ae5b4013ae9605feaff56ba937d1b22c1a78316764af8f96274d9f449c5640282df277a3ac06e0530e8f760e8153c029aa2f05a27
7
- data.tar.gz: 4b71fb1cfd4851d58759ca443e9d17a365d485621d7c1763b570171557a89c79a52e67080f53c25f1d7c4057a2a4decd43e46df7aa34909dc627b2717668a77b
6
+ metadata.gz: 758367c980b07a1d57f63fd0272e16f4ac4a93c42e747b9da200891438e661cede3edde72bb23f25ceb3e8c35074c53a59cb0a7e141edcb78684569163134deb
7
+ data.tar.gz: 6250e519af65a9800d4bb41926adb1713ef8e12d22e4503bb8eb8369514ce82db1036e289b80d0bd0fa8fb5cdb5d2f92fc2dc6e9ce029f5fb4a873f872e8f310
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## HEAD
2
2
 
3
+ ## 4.1.2
4
+
5
+ - Fix: Background task name lookup is now lazy, this fixes a bug when using `:::>- pre.erb background.start(...)` (https://github.com/zombocom/rundoc/pull/95)
6
+
7
+ ## 4.1.1
8
+
9
+ - Fix: Visibility forwarding for `pre.erb` was accidentally reversed, this is now fixed. (https://github.com/zombocom/rundoc/pull/93)
10
+
3
11
  ## 4.1.0
4
12
 
5
13
  - Add: Rundoc command `pre.erb` command used for dynamically templating any command using ERB syntax. (https://github.com/zombocom/rundoc/pull/90)
data/README.md CHANGED
@@ -74,7 +74,7 @@ This will generate a project folder with your project in it, and a markdown `REA
74
74
  - [$](#shell-commands)
75
75
  - [fail.$](#shell-commands)
76
76
  - Dynamic command templating
77
- - [pre.erb](#pre.erb)
77
+ - [pre.erb](#preerb)
78
78
  - Printing
79
79
  - [print.text](#print)
80
80
  - [print.erb](#print)
@@ -1,7 +1,12 @@
1
1
  class Rundoc::CodeCommand::Background::Log
2
2
  class Clear < Rundoc::CodeCommand
3
3
  def initialize(name:)
4
- @spawn = Rundoc::CodeCommand::Background::ProcessSpawn.find(name)
4
+ @name = name
5
+ @background = nil
6
+ end
7
+
8
+ def background
9
+ @background ||= Rundoc::CodeCommand::Background::ProcessSpawn.find(@name)
5
10
  end
6
11
 
7
12
  def to_md(env = {})
@@ -9,7 +14,7 @@ class Rundoc::CodeCommand::Background::Log
9
14
  end
10
15
 
11
16
  def call(env = {})
12
- @spawn.log.truncate(0)
17
+ background.log.truncate(0)
13
18
  ""
14
19
  end
15
20
  end
@@ -1,7 +1,12 @@
1
1
  class Rundoc::CodeCommand::Background::Log
2
2
  class Read < Rundoc::CodeCommand
3
3
  def initialize(name:)
4
- @spawn = Rundoc::CodeCommand::Background::ProcessSpawn.find(name)
4
+ @name = name
5
+ @background = nil
6
+ end
7
+
8
+ def background
9
+ @background ||= Rundoc::CodeCommand::Background::ProcessSpawn.find(@name)
5
10
  end
6
11
 
7
12
  def to_md(env = {})
@@ -9,7 +14,7 @@ class Rundoc::CodeCommand::Background::Log
9
14
  end
10
15
 
11
16
  def call(env = {})
12
- @spawn.log.read
17
+ background.log.read
13
18
  end
14
19
  end
15
20
  end
@@ -3,20 +3,28 @@ require "tempfile"
3
3
  class Rundoc::CodeCommand::Background
4
4
  class Start < Rundoc::CodeCommand
5
5
  def initialize(command, name:, wait: nil, timeout: 5, log: Tempfile.new("log"), out: "2>&1", allow_fail: false)
6
+ @timeout = timeout
6
7
  @command = command
7
8
  @name = name
8
9
  @wait = wait
9
10
  @allow_fail = allow_fail
10
- FileUtils.touch(log)
11
+ @log = log
12
+ @redirect = out
13
+ FileUtils.touch(@log)
11
14
 
12
- @spawn = ProcessSpawn.new(
15
+ @background = nil
16
+ end
17
+
18
+ def background
19
+ @background ||= ProcessSpawn.new(
13
20
  @command,
14
- timeout: timeout,
15
- log: log,
16
- out: out
17
- )
18
- puts "Spawning commmand: `#{@spawn.command}`"
19
- ProcessSpawn.add(@name, @spawn)
21
+ timeout: @timeout,
22
+ log: @log,
23
+ out: @redirect
24
+ ).tap do |spawn|
25
+ puts "Spawning commmand: `#{spawn.command}`"
26
+ ProcessSpawn.add(@name, spawn)
27
+ end
20
28
  end
21
29
 
22
30
  def to_md(env = {})
@@ -24,14 +32,14 @@ class Rundoc::CodeCommand::Background
24
32
  end
25
33
 
26
34
  def call(env = {})
27
- @spawn.wait(@wait)
28
- @spawn.check_alive! unless @allow_fail
35
+ background.wait(@wait)
36
+ background.check_alive! unless @allow_fail
29
37
 
30
- @spawn.log.read
38
+ background.log.read
31
39
  end
32
40
 
33
41
  def alive?
34
- !!@spawn.alive?
42
+ !!background.alive?
35
43
  end
36
44
  end
37
45
  end
@@ -6,10 +6,15 @@ class Rundoc::CodeCommand::Background
6
6
  def initialize(contents, name:, wait:, timeout: 5, ending: $/)
7
7
  @contents = contents
8
8
  @ending = ending
9
- @spawn = Rundoc::CodeCommand::Background::ProcessSpawn.find(name)
10
9
  @wait = wait
10
+ @name = name
11
11
  @timeout_value = Integer(timeout)
12
12
  @contents_written = nil
13
+ @background = nil
14
+ end
15
+
16
+ def background
17
+ @background ||= Rundoc::CodeCommand::Background::ProcessSpawn.find(@name)
13
18
  end
14
19
 
15
20
  # The command is rendered (`:::>-`) by the output of the `def call` method.
@@ -20,11 +25,11 @@ class Rundoc::CodeCommand::Background
20
25
  # The contents produced by the command (`:::->`) are rendered by the `def to_md` method.
21
26
  def call(env = {})
22
27
  writecontents
23
- @spawn.log.read
28
+ background.log.read
24
29
  end
25
30
 
26
31
  def writecontents
27
- @contents_written ||= @spawn.stdin_write(
32
+ @contents_written ||= background.stdin_write(
28
33
  contents,
29
34
  wait: @wait,
30
35
  ending: @ending,
@@ -1,7 +1,12 @@
1
1
  class Rundoc::CodeCommand::Background
2
2
  class Stop < Rundoc::CodeCommand
3
3
  def initialize(name:)
4
- @spawn = Rundoc::CodeCommand::Background::ProcessSpawn.find(name)
4
+ @name = name
5
+ @background = nil
6
+ end
7
+
8
+ def background
9
+ @background ||= Rundoc::CodeCommand::Background::ProcessSpawn.find(@name)
5
10
  end
6
11
 
7
12
  def to_md(env = {})
@@ -9,8 +14,8 @@ class Rundoc::CodeCommand::Background
9
14
  end
10
15
 
11
16
  def call(env = {})
12
- @spawn.stop
13
- @spawn.log.read
17
+ background.stop
18
+ background.log.read
14
19
  end
15
20
  end
16
21
  end
@@ -1,9 +1,14 @@
1
1
  class Rundoc::CodeCommand::Background
2
2
  class Wait < Rundoc::CodeCommand
3
3
  def initialize(name:, wait:, timeout: 5)
4
- @spawn = Rundoc::CodeCommand::Background::ProcessSpawn.find(name)
4
+ @name = name
5
5
  @wait = wait
6
6
  @timeout_value = Integer(timeout)
7
+ @background = nil
8
+ end
9
+
10
+ def background
11
+ @background ||= Rundoc::CodeCommand::Background::ProcessSpawn.find(name)
7
12
  end
8
13
 
9
14
  def to_md(env = {})
@@ -11,7 +16,7 @@ class Rundoc::CodeCommand::Background
11
16
  end
12
17
 
13
18
  def call(env = {})
14
- @spawn.wait(@wait, @timeout_value)
19
+ background.wait(@wait, @timeout_value)
15
20
  ""
16
21
  end
17
22
  end
@@ -27,8 +27,8 @@ class Rundoc::CodeCommand
27
27
  def code
28
28
  @code ||= begin
29
29
  vis = +""
30
- vis += @render_delegate_result ? ">" : "-"
31
30
  vis += @render_delegate_command ? ">" : "-"
31
+ vis += @render_delegate_result ? ">" : "-"
32
32
  code = [@line, @contents]
33
33
  .compact
34
34
  .reject(&:empty?)
@@ -1,3 +1,3 @@
1
1
  module Rundoc
2
- VERSION = "4.1.0"
2
+ VERSION = "4.1.2"
3
3
  end
@@ -1,6 +1,50 @@
1
1
  require "test_helper"
2
2
 
3
3
  class IntegrationPreErb < Minitest::Test
4
+ def test_result_visibility_forwarding
5
+ contents = <<~RUBY
6
+ ```
7
+ :::-> pre.erb $ echo <%= 1 + 1 %>
8
+ ```
9
+ RUBY
10
+
11
+ Dir.mktmpdir do |dir|
12
+ Dir.chdir(dir) do
13
+ expected = <<~EOF
14
+ ```
15
+ 2
16
+ ```
17
+ EOF
18
+
19
+ parsed = parse_contents(contents)
20
+ actual = parsed.to_md.gsub(Rundoc::FencedCodeBlock::AUTOGEN_WARNING, "").strip
21
+ assert_equal expected.strip, actual.strip
22
+ end
23
+ end
24
+ end
25
+
26
+ def test_command_visibility_forwarding
27
+ contents = <<~RUBY
28
+ ```
29
+ :::>- pre.erb $ echo <%= 1 + 1 %>
30
+ ```
31
+ RUBY
32
+
33
+ Dir.mktmpdir do |dir|
34
+ Dir.chdir(dir) do
35
+ expected = <<~EOF
36
+ ```
37
+ $ echo 2
38
+ ```
39
+ EOF
40
+
41
+ parsed = parse_contents(contents)
42
+ actual = parsed.to_md.gsub(Rundoc::FencedCodeBlock::AUTOGEN_WARNING, "").strip
43
+ assert_equal expected.strip, actual.strip
44
+ end
45
+ end
46
+ end
47
+
4
48
  def test_file_write
5
49
  key = SecureRandom.hex
6
50
  contents = <<~RUBY
@@ -4,15 +4,19 @@ class BackgroundTest < Minitest::Test
4
4
  def test_stdin_with_cat_echo
5
5
  Dir.mktmpdir do |dir|
6
6
  Dir.chdir(dir) do
7
- background_start = Rundoc::CodeCommand::Background::Start.new("cat",
8
- name: "cat")
9
- background_start.call
10
-
11
- output = Rundoc::CodeCommand::Background::StdinWrite.new(
7
+ # Intentionally out of order, should not raise an error as long as "cat"
8
+ # command exists at execution time
9
+ stdin_write = Rundoc::CodeCommand::Background::StdinWrite.new(
12
10
  "hello there",
13
11
  name: "cat",
14
12
  wait: "hello"
15
- ).call
13
+ )
14
+
15
+ background_start = Rundoc::CodeCommand::Background::Start.new("cat",
16
+ name: "cat")
17
+
18
+ background_start.call
19
+ output = stdin_write.call
16
20
  assert_equal("hello there" + $/, output)
17
21
 
18
22
  Rundoc::CodeCommand::Background::Log::Clear.new(
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rundoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 4.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Schneeman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-12-11 00:00:00.000000000 Z
11
+ date: 2024-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor