keepgoing 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: 14820183bb25ef55e7878bbe1ce3fdf6c87bafc64a71102d8462a67f4eae927e
4
- data.tar.gz: 0fbbf1c8ed8c9383a5089e56309f458d2d56dc28af7969a500108c53650110d6
3
+ metadata.gz: 2589b8ca550c4838aa6d26a76db23d1f838e145bc1c5bf708cd5e2c2fee96c0b
4
+ data.tar.gz: 8f07d3c67fd50d5061dc6d52cd6388273211296aca33a83b95a247144d2156e0
5
5
  SHA512:
6
- metadata.gz: a163e5125850e0665485309151b5d642fb164fe75928307d5c1b59ab390b4bee2a1ee4dc4f3ba5bbee1eea46e3101fc786a304bffa0e270c77a8ba70610b31e0
7
- data.tar.gz: ffbd4e5f2876f85a2aa22111afa91c00b9048111cd7d372a747be65bbb3552c2a569d3070011daa754bcacec398371489073d730f1375fa142f5c501260f6a9d
6
+ metadata.gz: 928419241425b2e3a7eabd2adf89bbd4289bb2acdc2adda598a52959d2eef0c43b786af87050bf0823f35ec6238abe06e98fdf6953ef41a04df769d41617063a
7
+ data.tar.gz: 937ec8924b4666e4d31beb1f6b9c6238968667104aaaf441441771410d1629d58c7a3e796649f542346167859b04397e54ed5886d467ff0043bbc3f942c4438d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- keepgoing (0.1.0)
4
+ keepgoing (0.2.0)
5
5
  guard (~> 2.18)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Keepgoing
2
2
 
3
+ https://user-images.githubusercontent.com/467114/168008226-333aeec1-2318-42c1-876b-33096f5010f0.mp4
4
+
3
5
  keepgoing uses [guard](https://github.com/guard/guard) to tighten the feedback loop on your single-file Ruby script that uses [bundler/inline](https://bundler.io/guides/bundler_in_a_single_file_ruby_script.html).
4
6
  When added as a gem to your script, it will run your script once when started like you are used to, but it won't exit and rather keep it going and re-run it every time you modify your script. You keep tinkering and once you save your script runs again and you 💥 immediately see the result 🤯.
5
7
 
@@ -30,11 +32,16 @@ puts "Woohoo"
30
32
  When you run this script in a terminal with `ruby test.rb`, it will execute like it would without keepgoing, printing out "Woohoo".
31
33
  But you'll notice it won't exit back to your terminal prompt. If you go back to your editor and change something, say add another `puts` and save, you'll notice it gets executed again and you see the results of your edit right away.
32
34
 
35
+ ### long-running or blocking scripts
36
+ If your script has not finished running until you save the next time, whatever it is still doing will be stopped and it will be forced to exit, so keepgoing can run it again with your latest changes.
37
+ This could be either great, because it allows you to use keepgoing even for things that run something blocking (like a web server that's waiting for requests), or it could be unexpected if keepgoing terminates something that is just taking a long time to finish processing.
38
+ Anyway, be aware that when you save, your script will be restarted, no matter what.
39
+
33
40
  ## Development
34
41
 
35
42
  After checking out the repo, run `bin/setup` to install dependencies.
36
43
 
37
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
44
+ To install this gem onto your local machine, run `bin/rake install`. To release a new version, update the version number in `version.rb`, and then run `bin/rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
38
45
 
39
46
  ## Contributing
40
47
 
data/keepgoing.gemspec CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.description = <<~DESC
13
13
  This gem is intended for use in a single file Ruby script that uses bundler/inline.
14
14
  You start your script once with `ruby your-script.rb` and keepgoing will take control,
15
- and re-run you script every time you save your script.
15
+ and re-run your script every time you save your script.
16
16
  You can concentrate on tinkering, while keepgoing will, well keep going,
17
17
  providing you with a fast and effortless feedback loop for your ruby experiments.
18
18
  DESC
@@ -16,6 +16,7 @@ module ::Guard
16
16
  def start
17
17
  @runs = 1
18
18
  puts "Hi! I'll keepgoing until you press Ctrl+C. Just edit and save away, you can do this 🎉\n\n"
19
+ setup_interrupt_handler
19
20
  run_all
20
21
  end
21
22
 
@@ -31,11 +32,39 @@ module ::Guard
31
32
  private
32
33
 
33
34
  def do_run
35
+ kill_running
36
+
34
37
  @runs += 1
35
- load options[:file]
38
+ fork_and_load
36
39
  rescue ScriptError, StandardError => e
37
40
  # prevent any script errors from stopping guard/keepgoing, but print error
38
41
  puts e.inspect
39
42
  end
43
+
44
+ def kill_running
45
+ return unless @pid
46
+
47
+ Process.kill("HUP", @pid)
48
+ rescue Errno::ESRCH, RangeError
49
+ # process was probably already gone, ignore
50
+ ensure
51
+ @pid = nil
52
+ end
53
+
54
+ def fork_and_load
55
+ @pid = fork do
56
+ Signal.trap("HUP") { exit }
57
+ load options[:file]
58
+ end
59
+ # detach script execution to give control back to guard
60
+ Process.detach(@pid)
61
+ end
62
+
63
+ def setup_interrupt_handler
64
+ Signal.trap("INT") do
65
+ kill_running
66
+ exit
67
+ end
68
+ end
40
69
  end
41
70
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Keepgoing
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keepgoing
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
  - Wolfgang Rittner
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-11 00:00:00.000000000 Z
11
+ date: 2022-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: guard
@@ -27,7 +27,7 @@ dependencies:
27
27
  description: |
28
28
  This gem is intended for use in a single file Ruby script that uses bundler/inline.
29
29
  You start your script once with `ruby your-script.rb` and keepgoing will take control,
30
- and re-run you script every time you save your script.
30
+ and re-run your script every time you save your script.
31
31
  You can concentrate on tinkering, while keepgoing will, well keep going,
32
32
  providing you with a fast and effortless feedback loop for your ruby experiments.
33
33
  email: