sack_race 1.0.0.rc1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1498684f3df3d6be627b01f8c20c8e5d7b8697cc312a57ff6806d9f6a0b0c910
4
+ data.tar.gz: 16ddd6862af4847f77044c147609ebee5787f2b06cce9392811dc661f240efdc
5
+ SHA512:
6
+ metadata.gz: 686eaf249eec247483c6c1f914c1b0d0eda80dc84535b304e6dac7196eb06575d03f1d8f1b904b06cd0602619b47e41f641b9b0849fc76716cfa79f9637eec79
7
+ data.tar.gz: 8a01fa9788dbca097e9a68716b429ccf67be442cc3db46b6a51ad34a569d5768e0ce89e9f8286be0b476ac20aa874b0e218dca514c1a3e06c00623514262ba0c
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.4.1
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # CHANGELOG
2
+
3
+ ## 1.0.0.rc1 (2025-04-08)
4
+
5
+ * Add initial implementation ([#2][])
6
+
7
+ [#2]: https://github.com/nickcharlton/sack_race/pull/2
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Nick Charlton
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # SackRace
2
+
3
+ A process manager that allows you to trigger and wait for events in output.
4
+
5
+ ## Installation
6
+
7
+ You can install `sack_race` via RubyGems: `gem install sack_race`
8
+
9
+ ## Usage
10
+
11
+ ```ruby
12
+ # define the process we want to run
13
+ process = SackRace::Process.new("bundle exec rails server")
14
+
15
+ # add an event to wait for and start
16
+ process.add_handler(:ready, "Use Ctrl-C to stop\n")
17
+ process.start
18
+
19
+ # block until the handler is called
20
+ process.wait_for_handler(:ready)
21
+ ```
22
+
23
+ ## Contributing
24
+
25
+ Bug reports and pull requests are welcome on [GitHub][].
26
+
27
+ This project is intended to be a safe, welcoming space for collaboration, and
28
+ contributors are expected to adhere to the [code of conduct][].
29
+
30
+ [GitHub]: https://github.com/nickcharlton/sack_race
31
+ [code of conduct]: https://github.com/nickcharlton/sack_race/blob/main/CODE_OF_CONDUCT.md
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ require "standard/rake"
7
+
8
+ task default: %i[spec standard]
@@ -0,0 +1,96 @@
1
+ require "open3"
2
+
3
+ module SackRace
4
+ class Process
5
+ attr_reader :command, :opts, :verbose
6
+
7
+ def initialize(command, opts = {})
8
+ @command = command
9
+ @verbose = opts.delete(:verbose)
10
+ @opts = opts
11
+ @handlers = {}
12
+ end
13
+
14
+ def add_handler(name, matching_string, &block)
15
+ @handlers[name] = Handler.new(name, matching_string, block)
16
+ end
17
+
18
+ def start
19
+ @running_thread = Thread.new do
20
+ run_subprocess(command, opts) do |stdout, stderr, thread|
21
+ puts stdout if verbose
22
+ warn stderr if verbose
23
+
24
+ @handlers.each do |name, handler|
25
+ if handler.match?(stdout)
26
+ handler.set_continue
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ def stop
34
+ ::Process.kill("INT", subprocess_thread.pid)
35
+ running_thread.join
36
+ end
37
+
38
+ def wait_for_handler(name)
39
+ handler = @handlers[name]
40
+ handler.wait
41
+ end
42
+
43
+ private
44
+
45
+ attr_reader :handlers, :running_thread, :subprocess_thread
46
+
47
+ def run_subprocess(cmd, opts, &block)
48
+ Open3.popen3(cmd, opts) do |stdin, stdout, stderr, thread|
49
+ @subprocess_thread = thread
50
+ readers = {out: stdout, err: stderr}.map do |key, stream|
51
+ Thread.new do
52
+ until (line = stream.gets).nil?
53
+ if block_given?
54
+ if key == :out
55
+ yield line, nil, thread
56
+ else
57
+ yield nil, line, thread
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ thread.join # don't exit until the external process is done
65
+ readers.map(&:join) # ensure we clear out open buffers
66
+ end
67
+ end
68
+ end
69
+
70
+ class Handler
71
+ def initialize(name, matching_string, block)
72
+ @name = name
73
+ @matching_string = matching_string
74
+ @block = block
75
+ @continue = false
76
+ @thread = Thread.new do
77
+ until @continue
78
+ sleep 1
79
+ end
80
+ end
81
+ end
82
+
83
+ def set_continue
84
+ @continue = true
85
+ end
86
+
87
+ def match?(stdout)
88
+ @matching_string == stdout
89
+ end
90
+
91
+ def wait
92
+ @thread.join
93
+ @block&.call
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,3 @@
1
+ module SackRace
2
+ VERSION = "1.0.0.rc1"
3
+ end
data/lib/sack_race.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "open3"
2
+
3
+ require_relative "sack_race/version"
4
+ require_relative "sack_race/process"
5
+
6
+ module SackRace
7
+ class Error < StandardError; end
8
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sack_race
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.rc1
5
+ platform: ruby
6
+ authors:
7
+ - Nick Charlton
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 2025-04-08 00:00:00.000000000 Z
11
+ dependencies: []
12
+ email:
13
+ - nick@nickcharlton.net
14
+ executables: []
15
+ extensions: []
16
+ extra_rdoc_files: []
17
+ files:
18
+ - ".rspec"
19
+ - ".ruby-version"
20
+ - CHANGELOG.md
21
+ - CODE_OF_CONDUCT.md
22
+ - LICENSE.txt
23
+ - README.md
24
+ - Rakefile
25
+ - lib/sack_race.rb
26
+ - lib/sack_race/process.rb
27
+ - lib/sack_race/version.rb
28
+ homepage: https://github.com/nickcharlton/sack_race
29
+ licenses:
30
+ - MIT
31
+ metadata:
32
+ homepage_uri: https://github.com/nickcharlton/sack_race
33
+ source_code_uri: https://github.com/nickcharlton/sack_race
34
+ changelog_uri: https://github.com/nickcharlton/sack_race/blob/main/CHANGELOG.md
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 3.1.0
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubygems_version: 3.6.2
50
+ specification_version: 4
51
+ summary: Manage processes with in progress callbacks
52
+ test_files: []