Skip to content

Commit 12c6669

Browse files
committed
support pre-boot hooks
1 parent 770b2b1 commit 12c6669

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,9 @@ settings. Note that `~/.spring.rb` is loaded *before* bundler, but
294294
projects without having to be added to the project's Gemfile, require
295295
them in your `~/.spring.rb`.
296296

297+
`config/spring_preboot.rb` is also loaded before bundler and before a
298+
server process is started, it can be used to add new top-level commands.
299+
297300
### Application root
298301

299302
Spring must know how to find your Rails application. If you have a

lib/spring/client.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,9 @@ def self.command_for(name)
3636
end
3737
end
3838
end
39+
40+
# allow users to add hooks that do not run in the server
41+
# or modify start/stop
42+
if File.exist?("config/spring_preboot.rb")
43+
require "./config/spring_preboot.rb"
44+
end

lib/spring/test/acceptance_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,13 @@ def exec_name
262262
assert_success "bin/rails runner 'puts 2'", stdout: "!callback!\n2"
263263
end
264264

265+
test "can define preboot tasks" do
266+
File.write("#{app.spring_config.sub('.rb', '_preboot.rb')}", <<-RUBY)
267+
Spring::Client::COMMANDS["foo"] = lambda { |args| puts "bar -- \#{args.inspect}" }
268+
RUBY
269+
assert_success "bin/spring foo --baz", stdout: "bar -- [\"foo\", \"--baz\"]\n"
270+
end
271+
265272
test "missing config/application.rb" do
266273
app.application_config.delete
267274
assert_failure "bin/rake -T", stderr: "unable to find your config/application.rb"

0 commit comments

Comments
 (0)