rb-process 0.1.0 → 0.2.0

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: fb024feedecacd42742fcfbd1d030fee5466b25ae1e8dc28aa07a05ff8a92fcf
4
- data.tar.gz: c1b62cdc11fce5cc67280683240fba904111f3cd0a774a20783c5ddc7a882aa3
3
+ metadata.gz: ab790cec5e95ea3f1ea4d012052d7475f74664d4442e5d64488e0eaebdc39542
4
+ data.tar.gz: 0cf40472af862fdde9b81b0e0541b69afb3a14dba3d05e826dc57a007a042ff1
5
5
  SHA512:
6
- metadata.gz: 405d0014ff27b89ac5d223ce3bbbd2006bb2bef70d1f5dad4284c2e9eb7d6ec49058e1a016e6b8a8a2ad19f69fc5aca012873cc71d1d5fb9473007e832db99c0
7
- data.tar.gz: 7c063f3fd904ef415b72bf2be14213f3665f80e63e2bd6dc106e2390f08361789cd52f32cfe3bdcda207136f9d1f4562f5e0edcc3751735a6f279468601848d2
6
+ metadata.gz: eb46766cb0400392384051ea2dfcc5b730a0e1147c576ae5cc3be5d0fe21bd5b593e5f968009091397da70b00675a6b06d9d6f260d8b7fc0c9a44f0047c38896
7
+ data.tar.gz: ed178815ae250bbe906de430225eb54181e7caa51928a512951ffaa56d4328414f2f0897199a5737b6dd3cb9afe4b6201a9293689a010af22676c42ef90e4cf5
data/.rubocop.yml CHANGED
@@ -3,3 +3,21 @@ inherit_gem:
3
3
 
4
4
  Metrics/MethodLength:
5
5
  Enabled: false
6
+
7
+ Metrics/BlockLength:
8
+ Enabled: false
9
+
10
+ Metrics/AbcSize:
11
+ Enabled: false
12
+
13
+ Metrics/CyclomaticComplexity:
14
+ Enabled: false
15
+
16
+ Metrics/PerceivedComplexity:
17
+ Enabled: false
18
+
19
+ Style/ConditionalAssignment:
20
+ Enabled: false
21
+
22
+ Style/GlobalStdStream:
23
+ Enabled: false
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Process
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/rb/process.rb CHANGED
@@ -1,22 +1,75 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "multi_io"
4
+ require "stringio"
3
5
  require_relative "process/version"
4
6
 
5
7
  module Process
6
- def self.run(*args, **options)
7
- result = String.new
8
- IO.popen(*args, **options) do |pipe|
9
- if block_given?
10
- yield pipe
11
- pipe.close_write
12
- end
13
- while !pipe.eof
14
- line = pipe.gets
15
- print line
16
- result << line
8
+ def self.run(*args, output: STDOUT, error: STDERR, **options)
9
+ output_strio = StringIO.new
10
+ error_strio = StringIO.new
11
+
12
+ output_writter = if !output.is_a?(IO)
13
+ output
14
+ elsif output != STDOUT
15
+ MultiIO.new(STDOUT, output, output_strio)
16
+ else
17
+ MultiIO.new(STDOUT, output_strio)
18
+ end
19
+ error_writter = if !error.is_a?(IO)
20
+ error
21
+ elsif error != STDERR
22
+ MultiIO.new(STDERR, error, error_strio)
23
+ else
24
+ MultiIO.new(STDERR, error_strio)
25
+ end
26
+
27
+ # spawn don't support MultiIO nor StringIO
28
+ in_r, in_w = IO.pipe
29
+ out_r, out_w = IO.pipe
30
+ err_r, err_w = IO.pipe
31
+
32
+ # override the options, so put the option after the options
33
+ pid = spawn(*args, **options, in: in_r, out: out_w, err: err_w)
34
+
35
+ if block_given?
36
+ begin
37
+ yield in_w, out_r, err_r
38
+ rescue StandardError => e
39
+ Process.detach(pid)
40
+ raise e
17
41
  end
18
42
  end
19
- result
43
+
44
+ in_w.close
45
+ out_w.close
46
+ err_w.close
47
+
48
+ out_r.each_line do |line|
49
+ output_writter.write(line)
50
+ end
51
+
52
+ err_r.each_line do |line|
53
+ error_writter.write(line)
54
+ end
55
+
56
+ in_r.close
57
+ out_r.close
58
+ err_r.close
59
+
60
+ pid, status = Process.wait2(pid)
61
+
62
+ output.close unless !output.is_a?(IO) || output == STDOUT
63
+ error.close unless !error.is_a?(IO) || error == STDERR
64
+ output_strio.close
65
+ error_strio.close
66
+
67
+ case status.success?
68
+ when true
69
+ output_strio.string
70
+ else
71
+ [output_strio.string, error_strio.string, status]
72
+ end
20
73
  end
21
74
 
22
75
  def self.output(...)
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rb-process
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - initdc
8
+ autorequire:
8
9
  bindir: exe
9
10
  cert_chain: []
10
- date: 2025-11-04 00:00:00.000000000 Z
11
+ date: 2026-02-19 00:00:00.000000000 Z
11
12
  dependencies: []
12
13
  description: Add the missing methods to the Ruby Process, you can use it with method
13
14
  chaining
@@ -33,6 +34,7 @@ metadata:
33
34
  homepage_uri: https://github.com/initdc/rb-process
34
35
  source_code_uri: https://github.com/initdc/rb-process.git
35
36
  changelog_uri: https://github.com/initdc/rb-process/blob/master/CHANGELOG.md
37
+ post_install_message:
36
38
  rdoc_options: []
37
39
  require_paths:
38
40
  - lib
@@ -47,7 +49,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
47
49
  - !ruby/object:Gem::Version
48
50
  version: '0'
49
51
  requirements: []
50
- rubygems_version: 3.6.2
52
+ rubygems_version: 3.5.22
53
+ signing_key:
51
54
  specification_version: 4
52
55
  summary: Add the missing methods to the Ruby Process, you can use it with method chaining
53
56
  test_files: []