ezcapture 1.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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +15 -0
  3. data/lib/ezcapture.rb +74 -0
  4. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c5f60156eb6c86308373d01e8eedae2b96e3a4418af394a8d75089b661f42f6e
4
+ data.tar.gz: b0be9f513422b2d8e734d84c38856bb1400ef5b287652a0ba384889bd4b2980c
5
+ SHA512:
6
+ metadata.gz: 5cc37e48577657e15ff6fe2103dd1fb67adccf8fbe153e77dd0a3c3257faaa8ae6c77ca20668824af72f816a24da3791c4f71b5d31eb1a249973ea92d66a8bbe
7
+ data.tar.gz: 6508b7ec1070dbe99025b675faae4e2d73139adf1278c5c427bb60a9e8f2e905ee85b5380dff658133e787d1239848d582c7f84064e8616e2399162291e49086
data/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # EzCapture
2
+
3
+ EzCapture provides a simple way to run a system process and capture the results.
4
+ EzCapture is a thin layer over Open3.capture.
5
+
6
+ ## Author
7
+
8
+ Mike O'Sullivan
9
+ mike@idocs.com
10
+
11
+ ## History
12
+
13
+ | version | date | notes |
14
+ |---------|---------------|-------------------------------|
15
+ | 1.0 | June 24, 2023 | Initial upload. |
data/lib/ezcapture.rb ADDED
@@ -0,0 +1,74 @@
1
+ require 'open3'
2
+
3
+ class EzCapture
4
+ # version
5
+ VERSION = '1.0'
6
+
7
+ # The command sent to Open3.capture
8
+ # @!attribute [r] cmd
9
+ # @return [Array] individual strings in the command
10
+ attr_reader :cmd
11
+
12
+ # Array returned by Open3.capture
13
+ # @return [Array]
14
+ attr_reader :results
15
+
16
+ # Error object if command failed
17
+ # @return [Errno::ENOENT]
18
+ attr_reader :error
19
+
20
+ # @param p_cmd [Array] one or more strings to send as a command
21
+ def initialize(*p_cmd)
22
+ super()
23
+ @results = nil
24
+ @error = nil
25
+
26
+ # flatten command
27
+ @cmd = p_cmd.flatten.clone
28
+
29
+ # attempt to run command
30
+ begin
31
+ @results = Open3.capture3(*cmd)
32
+
33
+ # catch errors
34
+ rescue => e
35
+ @error = e
36
+ end
37
+ end
38
+
39
+ # @return [String] STDOUT from the command
40
+ def stdout
41
+ if @results
42
+ return @results[0]
43
+ else
44
+ return nil
45
+ end
46
+ end
47
+
48
+ # @return [String] STDERR from the command
49
+ def stderr
50
+ if @results
51
+ return @results[1]
52
+ else
53
+ return nil
54
+ end
55
+ end
56
+
57
+ # @return [Process::Status] status of running the command
58
+ def status
59
+ if @results
60
+ return @results[2]
61
+ else
62
+ return nil
63
+ end
64
+ end
65
+
66
+ # @return [Boolean] success or failure of the command
67
+ def success?
68
+ if status
69
+ return @results[2].success?
70
+ else
71
+ return false
72
+ end
73
+ end
74
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ezcapture
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Mike O'Sullivan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-06-24 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Thin layer over Open3.capture
14
+ email: mike@idocs.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - README.md
20
+ - lib/ezcapture.rb
21
+ homepage: https://github.com/mikosullivan/ezcapture
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubygems_version: 3.3.5
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: EzCapture
44
+ test_files: []