rundoc 4.1.1 → 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: 406f197901506713b700c1ff8511fb05904400f806c7dc9d1a134e2b04ab13ab
4
- data.tar.gz: 5b09bdd1560879915be2b52f1f36a13626fe2edfd696a14e66f90d5849b999fc
3
+ metadata.gz: 175e8af5e0beeb7acca8d32740f3379d68771ba207d723a1f51495848645249c
4
+ data.tar.gz: ac404b2c8337948628d7f18b90b20c57668f8a059d6e10c9c64354d21e04ac58
5
5
  SHA512:
6
- metadata.gz: '089c0ed9bb56187b8d18ff8eb55662ddf88f592329c028ff24478723bf044e87e75fbc6c84e903bb34bb3e111134a48a6b54861d6af1eb0e2cb9dc533a812da4'
7
- data.tar.gz: f616697430af9d1948d64a9a97a7902ccc3dfa8a61cc4bc4a5b7d3e109944ec50e1475b6889c1168fceba5a733b4d34adc5dd0d068ddff85fcfbff40ee2e8438
6
+ metadata.gz: 758367c980b07a1d57f63fd0272e16f4ac4a93c42e747b9da200891438e661cede3edde72bb23f25ceb3e8c35074c53a59cb0a7e141edcb78684569163134deb
7
+ data.tar.gz: 6250e519af65a9800d4bb41926adb1713ef8e12d22e4503bb8eb8369514ce82db1036e289b80d0bd0fa8fb5cdb5d2f92fc2dc6e9ce029f5fb4a873f872e8f310
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
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
+
3
7
  ## 4.1.1
4
8
 
5
9
  - Fix: Visibility forwarding for `pre.erb` was accidentally reversed, this is now fixed. (https://github.com/zombocom/rundoc/pull/93)
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Rundoc
2
- VERSION = "4.1.1"
2
+ VERSION = "4.1.2"
3
3
  end
@@ -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.1
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-13 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