spring 1.1.1 → 1.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 +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +4 -2
- data/CHANGELOG.md +28 -0
- data/CONTRIBUTING.md +20 -0
- data/Gemfile +0 -2
- data/README.md +27 -14
- data/Rakefile +1 -1
- data/bin/spring +16 -0
- data/lib/spring/application.rb +51 -23
- data/lib/spring/application_manager.rb +3 -0
- data/lib/spring/client/binstub.rb +1 -1
- data/lib/spring/client/rails.rb +1 -0
- data/lib/spring/client/run.rb +27 -2
- data/lib/spring/commands/rails.rb +43 -11
- data/lib/spring/commands.rb +11 -2
- data/lib/spring/env.rb +3 -3
- data/lib/spring/server.rb +2 -0
- data/lib/spring/sid.rb +1 -1
- data/lib/spring/test/acceptance_test.rb +333 -0
- data/{test/acceptance/helper.rb → lib/spring/test/application.rb} +15 -127
- data/lib/spring/test/application_generator.rb +121 -0
- data/lib/spring/test/rails_version.rb +40 -0
- data/lib/spring/test/watcher_test.rb +167 -0
- data/lib/spring/test.rb +15 -0
- data/lib/spring/version.rb +1 -1
- data/lib/spring/watcher/polling.rb +2 -0
- data/lib/spring/watcher.rb +4 -8
- data/test/acceptance_test.rb +4 -0
- data/test/helper.rb +2 -2
- data/test/unit/commands_test.rb +23 -1
- data/test/unit/watcher_test.rb +2 -188
- metadata +19 -17
- data/lib/spring/watcher/listen.rb +0 -52
- data/test/acceptance/app_test.rb +0 -334
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0bae3c5f77134086e25e77df5d700895438e16ba
|
|
4
|
+
data.tar.gz: 882c5139fed3fe573bb75136e683ca8ee3744069
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c5d7a1655a09f56c5663024af741c3c58fe9542418603a59dddb0c19ee24203a1527911a4626f6a5eedd5daf5b6e19b1107582fdc2c7528563af1878034cf1a7
|
|
7
|
+
data.tar.gz: d143cad1d9b6f15440d80aa300b566a4fa19c0c90deada7fa627e3b230f9199ed56eae911c0005fa2ff83814bf3e66190777a42e0bb4cf5ee6d997df9d06b297
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
|
@@ -2,8 +2,10 @@ language: ruby
|
|
|
2
2
|
rvm:
|
|
3
3
|
- 1.9.3
|
|
4
4
|
- 2.0.0
|
|
5
|
-
- 2.1.
|
|
5
|
+
- 2.1.2
|
|
6
6
|
env:
|
|
7
7
|
- RAILS_VERSION="~> 3.2.0"
|
|
8
8
|
- RAILS_VERSION="~> 4.0.0"
|
|
9
|
-
- RAILS_VERSION="~> 4.1.0
|
|
9
|
+
- RAILS_VERSION="~> 4.1.0"
|
|
10
|
+
before_script:
|
|
11
|
+
- travis_retry gem install rails --version "$RAILS_VERSION"
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
## 1.2.0
|
|
2
|
+
|
|
3
|
+
* Accept -e and --environment options for `rails console`.
|
|
4
|
+
* Watch `config/secrets.yml` by default. #289 - @morgoth
|
|
5
|
+
* Change monkey-patched `Kernel.raise` from public to private (to match default Ruby behavior) #351 - @mattbrictson
|
|
6
|
+
* Let application_id also respect RUBY_VERSION for the use case of switching between Ruby versions for a given Rails app - @methodmissing
|
|
7
|
+
* Extract the 'listen' watcher to a separate `spring-watcher-listen`
|
|
8
|
+
gem. This allows it to be developed/maintained separately.
|
|
9
|
+
|
|
10
|
+
## 1.1.3
|
|
11
|
+
|
|
12
|
+
* The `rails runner` command no longer passes environment switches to
|
|
13
|
+
files which it runs. Issue #272.
|
|
14
|
+
* Various issues solved to do with termination / processes hanging around
|
|
15
|
+
longer than they should. Issue #290.
|
|
16
|
+
|
|
17
|
+
## 1.1.2
|
|
18
|
+
|
|
19
|
+
* Detect old binstubs generated with Spring 1.0 and exit with an error.
|
|
20
|
+
This prevents a situation where you can get stuck in an infinite loop
|
|
21
|
+
of spring invocations.
|
|
22
|
+
* Avoid `warning: already initialized constant APP_PATH` when running
|
|
23
|
+
rails commands that do not use spring (e.g. `bin/rails server` would
|
|
24
|
+
emit this when you ^C to exit)
|
|
25
|
+
* Fix `reload!` in rails console
|
|
26
|
+
* Don't connect/disconnect the database if there are no connections
|
|
27
|
+
configured. Issue #256.
|
|
28
|
+
|
|
1
29
|
## 1.1.1
|
|
2
30
|
|
|
3
31
|
* Fix `$0` so that it is no longer prefixed with "spring ", as doing
|
data/CONTRIBUTING.md
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
# Don't use the issue tracker to ask questions
|
|
2
|
+
|
|
3
|
+
Please use Stack Overflow or similar. If you subsequently feel that the
|
|
4
|
+
documentation is inadequate then plase submit a pull request to fix it.
|
|
5
|
+
|
|
1
6
|
# Contributing guide
|
|
2
7
|
|
|
3
8
|
## Getting set up
|
|
@@ -30,3 +35,18 @@ $ RAILS_VERSION="~> 3.2.0" rake test:acceptance
|
|
|
30
35
|
|
|
31
36
|
The apps in `test/apps` will be named based on the rails version and the
|
|
32
37
|
spring version.
|
|
38
|
+
|
|
39
|
+
## Testing with your app
|
|
40
|
+
|
|
41
|
+
You cannot link to a git repo from your Gemfile. Spring doesn't support
|
|
42
|
+
this due to the way that it gets loaded (bypassing bundler for
|
|
43
|
+
performance reasons).
|
|
44
|
+
|
|
45
|
+
Therefore, to test changes with your app, run `rake install` to properly
|
|
46
|
+
install the gem on your system.
|
|
47
|
+
|
|
48
|
+
## Submitting a pull request
|
|
49
|
+
|
|
50
|
+
If your change is a bugfix or feature, please make sure you add to
|
|
51
|
+
`CHANGELOG.md` under the "Next Release" heading (add the heading if
|
|
52
|
+
needed).
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -7,8 +7,6 @@ Spring is a Rails application preloader. It speeds up development by
|
|
|
7
7
|
keeping your application running in the background so you don't need to
|
|
8
8
|
boot it every time you run a test, rake task or migration.
|
|
9
9
|
|
|
10
|
-
**Upgrading to 1.1? It's recommended to run `bundle exec spring binstub --all` to regenerate your binstubs.**
|
|
11
|
-
|
|
12
10
|
## Features
|
|
13
11
|
|
|
14
12
|
* Totally automatic; no need to explicitly start and stop the background process
|
|
@@ -19,7 +17,7 @@ boot it every time you run a test, rake task or migration.
|
|
|
19
17
|
## Compatibility
|
|
20
18
|
|
|
21
19
|
* Ruby versions: MRI 1.9.3, MRI 2.0, MRI 2.1
|
|
22
|
-
* Rails versions: 3.2, 4.0
|
|
20
|
+
* Rails versions: 3.2, 4.0 (in Rails 4.1 and up Spring is included by default)
|
|
23
21
|
|
|
24
22
|
Spring makes extensive use of `Process.fork`, so won't be able to
|
|
25
23
|
provide a speed up on platforms which don't support forking (Windows, JRuby).
|
|
@@ -34,6 +32,9 @@ Add spring to your Gemfile:
|
|
|
34
32
|
gem "spring", group: :development
|
|
35
33
|
```
|
|
36
34
|
|
|
35
|
+
(Note: using `gem "spring", git: "..."` *won't* work and is not a
|
|
36
|
+
supported way of using spring.)
|
|
37
|
+
|
|
37
38
|
It's recommended to 'springify' the executables in your `bin/`
|
|
38
39
|
directory:
|
|
39
40
|
|
|
@@ -58,8 +59,10 @@ will just be silently ignored and the lines after it will be executed as
|
|
|
58
59
|
normal.
|
|
59
60
|
|
|
60
61
|
If you don't want to prefix every command you type with `bin/`, you
|
|
61
|
-
can [use direnv](https://github.com/zimbatm/direnv) to
|
|
62
|
-
`./bin` to your `PATH` when you `cd` into your application.
|
|
62
|
+
can [use direnv](https://github.com/zimbatm/direnv#the-stdlib) to
|
|
63
|
+
automatically add `./bin` to your `PATH` when you `cd` into your application.
|
|
64
|
+
Simply create an `.envrc` file with the command `PATH_add bin` in your
|
|
65
|
+
Rails directory.
|
|
63
66
|
|
|
64
67
|
### Usage
|
|
65
68
|
|
|
@@ -176,6 +179,17 @@ To remove spring:
|
|
|
176
179
|
* 'Unspring' your bin/ executables: `bin/spring binstub --remove --all`
|
|
177
180
|
* Remove spring from your Gemfile
|
|
178
181
|
|
|
182
|
+
### Deployment
|
|
183
|
+
|
|
184
|
+
You must not install Spring on your production environment. To prevent it from
|
|
185
|
+
being installed, provide the `--without development test` argument to the
|
|
186
|
+
`bundle install` command which is used to install gems on your production
|
|
187
|
+
machines:
|
|
188
|
+
|
|
189
|
+
```
|
|
190
|
+
$ bundle install --without development test
|
|
191
|
+
```
|
|
192
|
+
|
|
179
193
|
## Commands
|
|
180
194
|
|
|
181
195
|
### `rake`
|
|
@@ -209,9 +223,11 @@ to pick up the changes):
|
|
|
209
223
|
|
|
210
224
|
* [spring-commands-rspec](https://github.com/jonleighton/spring-commands-rspec)
|
|
211
225
|
* [spring-commands-cucumber](https://github.com/jonleighton/spring-commands-cucumber)
|
|
226
|
+
* [spring-commands-spinach](https://github.com/jvanbaarsen/spring-commands-spinach)
|
|
212
227
|
* [spring-commands-testunit](https://github.com/jonleighton/spring-commands-testunit) - useful for
|
|
213
228
|
running `Test::Unit` tests on Rails 3, since only Rails 4 allows you
|
|
214
229
|
to use `rake test path/to/test` to run a particular test/directory.
|
|
230
|
+
* [spring-commands-teaspoon](https://github.com/alejandrobabio/spring-commands-teaspoon.git)
|
|
215
231
|
|
|
216
232
|
## Use without adding to bundle
|
|
217
233
|
|
|
@@ -294,7 +310,7 @@ Spring.application_root = './test/dummy'
|
|
|
294
310
|
|
|
295
311
|
There is no `Spring.before_fork` callback. To run something before the
|
|
296
312
|
fork, you can place it in `~/.spring.rb` or `config/spring.rb` or in any of the files
|
|
297
|
-
which get run when your application
|
|
313
|
+
which get run when your application initializes, such as
|
|
298
314
|
`config/application.rb`, `config/environments/*.rb` or
|
|
299
315
|
`config/initializers/*.rb`.
|
|
300
316
|
|
|
@@ -323,18 +339,15 @@ If there are additional files or directories which should trigger an
|
|
|
323
339
|
application restart, you can specify them with `Spring.watch`:
|
|
324
340
|
|
|
325
341
|
```ruby
|
|
326
|
-
Spring.watch "
|
|
342
|
+
Spring.watch "config/some_config_file.yml"
|
|
327
343
|
```
|
|
328
344
|
|
|
329
345
|
By default Spring polls the filesystem for changes once every 0.2 seconds. This
|
|
330
346
|
method requires zero configuration, but if you find that it's using too
|
|
331
|
-
much CPU, then you can
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
```
|
|
336
|
-
|
|
337
|
-
You may need to add the [`listen` gem](https://github.com/guard/listen) to your `Gemfile`.
|
|
347
|
+
much CPU, then you can use event-based file system listening by
|
|
348
|
+
installing the
|
|
349
|
+
[spring-watcher-listen](https://github.com/jonleighton/spring-watcher-listen)
|
|
350
|
+
gem.
|
|
338
351
|
|
|
339
352
|
## Troubleshooting
|
|
340
353
|
|
data/Rakefile
CHANGED
data/bin/spring
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
|
|
3
|
+
if defined?(Spring)
|
|
4
|
+
$stderr.puts "You've tried to invoke Spring when it's already loaded (i.e. the Spring " \
|
|
5
|
+
"constant is defined)."
|
|
6
|
+
$stderr.puts
|
|
7
|
+
$stderr.puts "This is probably because you generated binstubs with " \
|
|
8
|
+
"Spring 1.0, and you now have a Spring version > 1.0 on your system. To solve " \
|
|
9
|
+
"this, upgrade your bundle to the latest Spring version and then run " \
|
|
10
|
+
"`bundle exec spring binstub --all` to regenerate your binstubs. This is a one-time " \
|
|
11
|
+
"step necessary to upgrade from 1.0 to 1.1."
|
|
12
|
+
$stderr.puts
|
|
13
|
+
$stderr.puts "Here's the backtrace:"
|
|
14
|
+
$stderr.puts
|
|
15
|
+
$stderr.puts caller
|
|
16
|
+
exit 1
|
|
17
|
+
end
|
|
18
|
+
|
|
3
19
|
if defined?(Gem)
|
|
4
20
|
if Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.1.0")
|
|
5
21
|
warn "Warning: You're using Rubygems #{Gem::VERSION} with Spring. " \
|
data/lib/spring/application.rb
CHANGED
|
@@ -11,7 +11,7 @@ module Spring
|
|
|
11
11
|
@original_env = original_env
|
|
12
12
|
@spring_env = Env.new
|
|
13
13
|
@mutex = Mutex.new
|
|
14
|
-
@waiting =
|
|
14
|
+
@waiting = Set.new
|
|
15
15
|
@preloaded = false
|
|
16
16
|
@state = :initialized
|
|
17
17
|
@interrupt = IO.pipe
|
|
@@ -91,7 +91,9 @@ module Spring
|
|
|
91
91
|
|
|
92
92
|
require Spring.application_root_path.join("config", "environment")
|
|
93
93
|
|
|
94
|
+
@original_cache_classes = Rails.application.config.cache_classes
|
|
94
95
|
Rails.application.config.cache_classes = false
|
|
96
|
+
|
|
95
97
|
disconnect_database
|
|
96
98
|
|
|
97
99
|
@preloaded = :success
|
|
@@ -106,6 +108,9 @@ module Spring
|
|
|
106
108
|
if defined?(Rails) && Rails.application
|
|
107
109
|
watcher.add Rails.application.paths["config/initializers"]
|
|
108
110
|
watcher.add Rails.application.paths["config/database"]
|
|
111
|
+
if secrets_path = Rails.application.paths["config/secrets"]
|
|
112
|
+
watcher.add secrets_path
|
|
113
|
+
end
|
|
109
114
|
end
|
|
110
115
|
end
|
|
111
116
|
|
|
@@ -161,9 +166,13 @@ module Spring
|
|
|
161
166
|
# Load in the current env vars, except those which *were* changed when spring started
|
|
162
167
|
env.each { |k, v| ENV[k] ||= v }
|
|
163
168
|
|
|
164
|
-
# requiring is faster,
|
|
165
|
-
|
|
166
|
-
|
|
169
|
+
# requiring is faster, so if config.cache_classes was true in
|
|
170
|
+
# the environment's config file, then we can respect that from
|
|
171
|
+
# here on as we no longer need constant reloading.
|
|
172
|
+
if @original_cache_classes
|
|
173
|
+
ActiveSupport::Dependencies.mechanism = :require
|
|
174
|
+
Rails.application.config.cache_classes = true
|
|
175
|
+
end
|
|
167
176
|
|
|
168
177
|
connect_database
|
|
169
178
|
srand
|
|
@@ -180,21 +189,7 @@ module Spring
|
|
|
180
189
|
log "forked #{pid}"
|
|
181
190
|
manager.puts pid
|
|
182
191
|
|
|
183
|
-
|
|
184
|
-
Thread.new {
|
|
185
|
-
@mutex.synchronize { @waiting += 1 }
|
|
186
|
-
|
|
187
|
-
_, status = Process.wait2 pid
|
|
188
|
-
log "#{pid} exited with #{status.exitstatus}"
|
|
189
|
-
|
|
190
|
-
streams.each(&:close)
|
|
191
|
-
client.puts(status.exitstatus)
|
|
192
|
-
client.close
|
|
193
|
-
|
|
194
|
-
@mutex.synchronize { @waiting -= 1 }
|
|
195
|
-
exit_if_finished
|
|
196
|
-
}
|
|
197
|
-
|
|
192
|
+
wait pid, streams, client
|
|
198
193
|
rescue Exception => e
|
|
199
194
|
log "exception: #{e}"
|
|
200
195
|
manager.puts unless pid
|
|
@@ -209,7 +204,14 @@ module Spring
|
|
|
209
204
|
end
|
|
210
205
|
|
|
211
206
|
def terminate
|
|
212
|
-
|
|
207
|
+
if exiting?
|
|
208
|
+
# Ensure that we do not ignore subsequent termination attempts
|
|
209
|
+
log "forced exit"
|
|
210
|
+
@waiting.each { |pid| Process.kill("TERM", pid) }
|
|
211
|
+
Kernel.exit
|
|
212
|
+
else
|
|
213
|
+
state! :terminating
|
|
214
|
+
end
|
|
213
215
|
end
|
|
214
216
|
|
|
215
217
|
def exit
|
|
@@ -221,7 +223,7 @@ module Spring
|
|
|
221
223
|
|
|
222
224
|
def exit_if_finished
|
|
223
225
|
@mutex.synchronize {
|
|
224
|
-
Kernel.exit if exiting? && @waiting
|
|
226
|
+
Kernel.exit if exiting? && @waiting.empty?
|
|
225
227
|
}
|
|
226
228
|
end
|
|
227
229
|
|
|
@@ -246,11 +248,11 @@ module Spring
|
|
|
246
248
|
end
|
|
247
249
|
|
|
248
250
|
def disconnect_database
|
|
249
|
-
ActiveRecord::Base.remove_connection if
|
|
251
|
+
ActiveRecord::Base.remove_connection if active_record_configured?
|
|
250
252
|
end
|
|
251
253
|
|
|
252
254
|
def connect_database
|
|
253
|
-
ActiveRecord::Base.establish_connection if
|
|
255
|
+
ActiveRecord::Base.establish_connection if active_record_configured?
|
|
254
256
|
end
|
|
255
257
|
|
|
256
258
|
# This feels very naughty
|
|
@@ -268,6 +270,7 @@ module Spring
|
|
|
268
270
|
end
|
|
269
271
|
end
|
|
270
272
|
end
|
|
273
|
+
private :raise
|
|
271
274
|
end
|
|
272
275
|
end
|
|
273
276
|
|
|
@@ -289,5 +292,30 @@ module Spring
|
|
|
289
292
|
[STDOUT, STDERR].each { |stream| stream.reopen(spring_env.log_file) }
|
|
290
293
|
STDIN.reopen("/dev/null")
|
|
291
294
|
end
|
|
295
|
+
|
|
296
|
+
def wait(pid, streams, client)
|
|
297
|
+
@mutex.synchronize { @waiting << pid }
|
|
298
|
+
|
|
299
|
+
# Wait in a separate thread so we can run multiple commands at once
|
|
300
|
+
Thread.new {
|
|
301
|
+
begin
|
|
302
|
+
_, status = Process.wait2 pid
|
|
303
|
+
log "#{pid} exited with #{status.exitstatus}"
|
|
304
|
+
|
|
305
|
+
streams.each(&:close)
|
|
306
|
+
client.puts(status.exitstatus)
|
|
307
|
+
client.close
|
|
308
|
+
ensure
|
|
309
|
+
@mutex.synchronize { @waiting.delete pid }
|
|
310
|
+
exit_if_finished
|
|
311
|
+
end
|
|
312
|
+
}
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
private
|
|
316
|
+
|
|
317
|
+
def active_record_configured?
|
|
318
|
+
defined?(ActiveRecord::Base) && ActiveRecord::Base.configurations.any?
|
|
319
|
+
end
|
|
292
320
|
end
|
|
293
321
|
end
|
|
@@ -36,7 +36,7 @@ unless defined?(Spring)
|
|
|
36
36
|
require "rubygems"
|
|
37
37
|
require "bundler"
|
|
38
38
|
|
|
39
|
-
if match = Bundler.default_lockfile.read.match(/^GEM$.*?^ spring \((.*?)\)$.*?^$/m)
|
|
39
|
+
if match = Bundler.default_lockfile.read.match(/^GEM$.*?^ (?: )*spring \((.*?)\)$.*?^$/m)
|
|
40
40
|
ENV["GEM_PATH"] = ([Bundler.bundle_path.to_s] + Gem.path).join(File::PATH_SEPARATOR)
|
|
41
41
|
ENV["GEM_HOME"] = ""
|
|
42
42
|
Gem.paths = ENV
|
data/lib/spring/client/rails.rb
CHANGED
data/lib/spring/client/run.rb
CHANGED
|
@@ -5,6 +5,12 @@ module Spring
|
|
|
5
5
|
module Client
|
|
6
6
|
class Run < Command
|
|
7
7
|
FORWARDED_SIGNALS = %w(INT QUIT USR1 USR2 INFO) & Signal.list.keys
|
|
8
|
+
TIMEOUT = 1
|
|
9
|
+
|
|
10
|
+
def initialize(args)
|
|
11
|
+
super
|
|
12
|
+
@signal_queue = []
|
|
13
|
+
end
|
|
8
14
|
|
|
9
15
|
def log(message)
|
|
10
16
|
env.log "[client] #{message}"
|
|
@@ -20,6 +26,7 @@ module Spring
|
|
|
20
26
|
|
|
21
27
|
application, client = UNIXSocket.pair
|
|
22
28
|
|
|
29
|
+
queue_signals
|
|
23
30
|
connect_to_application(client)
|
|
24
31
|
run_command(client, application)
|
|
25
32
|
rescue Errno::ECONNRESET
|
|
@@ -59,7 +66,12 @@ ERROR
|
|
|
59
66
|
def connect_to_application(client)
|
|
60
67
|
server.send_io client
|
|
61
68
|
send_json server, "args" => args, "default_rails_env" => default_rails_env
|
|
62
|
-
|
|
69
|
+
|
|
70
|
+
if IO.select([server], [], [], TIMEOUT)
|
|
71
|
+
server.gets or raise CommandNotFound
|
|
72
|
+
else
|
|
73
|
+
raise "Error connecting to Spring server"
|
|
74
|
+
end
|
|
63
75
|
end
|
|
64
76
|
|
|
65
77
|
def run_command(client, application)
|
|
@@ -96,14 +108,23 @@ ERROR
|
|
|
96
108
|
application.close
|
|
97
109
|
end
|
|
98
110
|
|
|
111
|
+
def queue_signals
|
|
112
|
+
FORWARDED_SIGNALS.each do |sig|
|
|
113
|
+
trap(sig) { @signal_queue << sig }
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
99
117
|
def forward_signals(pid)
|
|
118
|
+
@signal_queue.each { |sig| kill sig, pid }
|
|
119
|
+
|
|
100
120
|
FORWARDED_SIGNALS.each do |sig|
|
|
101
121
|
trap(sig) { forward_signal sig, pid }
|
|
102
122
|
end
|
|
123
|
+
rescue Errno::ESRCH
|
|
103
124
|
end
|
|
104
125
|
|
|
105
126
|
def forward_signal(sig, pid)
|
|
106
|
-
|
|
127
|
+
kill(sig, pid)
|
|
107
128
|
rescue Errno::ESRCH
|
|
108
129
|
# If the application process is gone, then don't block the
|
|
109
130
|
# signal on this process.
|
|
@@ -111,6 +132,10 @@ ERROR
|
|
|
111
132
|
Process.kill(sig, Process.pid)
|
|
112
133
|
end
|
|
113
134
|
|
|
135
|
+
def kill(sig, pid)
|
|
136
|
+
Process.kill(sig, -Process.getpgid(pid))
|
|
137
|
+
end
|
|
138
|
+
|
|
114
139
|
def send_json(socket, data)
|
|
115
140
|
data = JSON.dump(data)
|
|
116
141
|
|
|
@@ -13,7 +13,19 @@ module Spring
|
|
|
13
13
|
|
|
14
14
|
class RailsConsole < Rails
|
|
15
15
|
def env(args)
|
|
16
|
-
args.first if args.first && !args.first.index("-")
|
|
16
|
+
return args.first if args.first && !args.first.index("-")
|
|
17
|
+
|
|
18
|
+
environment = nil
|
|
19
|
+
|
|
20
|
+
args.each.with_index do |arg, i|
|
|
21
|
+
if arg =~ /--environment=(\w+)/
|
|
22
|
+
environment = $1
|
|
23
|
+
elsif i > 0 && args[i - 1] == "-e"
|
|
24
|
+
environment = arg
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
environment
|
|
17
29
|
end
|
|
18
30
|
|
|
19
31
|
def command_name
|
|
@@ -34,21 +46,41 @@ module Spring
|
|
|
34
46
|
end
|
|
35
47
|
|
|
36
48
|
class RailsRunner < Rails
|
|
37
|
-
def
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
previous_option = option
|
|
45
|
-
end
|
|
46
|
-
nil
|
|
49
|
+
def call
|
|
50
|
+
ARGV.replace extract_environment(ARGV).first
|
|
51
|
+
super
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def env(args)
|
|
55
|
+
extract_environment(args).last
|
|
47
56
|
end
|
|
48
57
|
|
|
49
58
|
def command_name
|
|
50
59
|
"runner"
|
|
51
60
|
end
|
|
61
|
+
|
|
62
|
+
def extract_environment(args)
|
|
63
|
+
environment = nil
|
|
64
|
+
|
|
65
|
+
args = args.select.with_index { |arg, i|
|
|
66
|
+
case arg
|
|
67
|
+
when "-e"
|
|
68
|
+
false
|
|
69
|
+
when /--environment=(\w+)/
|
|
70
|
+
environment = $1
|
|
71
|
+
false
|
|
72
|
+
else
|
|
73
|
+
if i > 0 && args[i - 1] == "-e"
|
|
74
|
+
environment = arg
|
|
75
|
+
false
|
|
76
|
+
else
|
|
77
|
+
true
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
[args, environment]
|
|
83
|
+
end
|
|
52
84
|
end
|
|
53
85
|
|
|
54
86
|
Spring.register_command "rails_console", RailsConsole.new
|
data/lib/spring/commands.rb
CHANGED
|
@@ -32,8 +32,17 @@ module Spring
|
|
|
32
32
|
# then we need to be under bundler.
|
|
33
33
|
require "bundler/setup"
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
# Auto-require any spring extensions which are in the Gemfile
|
|
36
|
+
Gem::Specification.map(&:name).grep(/^spring-/).each do |command|
|
|
37
|
+
begin
|
|
38
|
+
require command
|
|
39
|
+
rescue LoadError => error
|
|
40
|
+
if error.message.include?(command)
|
|
41
|
+
require command.gsub("-", "/")
|
|
42
|
+
else
|
|
43
|
+
raise
|
|
44
|
+
end
|
|
45
|
+
end
|
|
37
46
|
end
|
|
38
47
|
|
|
39
48
|
config = File.expand_path("./config/spring.rb")
|
data/lib/spring/env.rb
CHANGED
|
@@ -16,7 +16,7 @@ module Spring
|
|
|
16
16
|
def initialize(root = nil)
|
|
17
17
|
@root = root
|
|
18
18
|
@project_root = root
|
|
19
|
-
@log_file = File.open(ENV["SPRING_LOG"] ||
|
|
19
|
+
@log_file = File.open(ENV["SPRING_LOG"] || File::NULL, "a")
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def root
|
|
@@ -32,13 +32,13 @@ module Spring
|
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
def tmp_path
|
|
35
|
-
path = Pathname.new(Dir.tmpdir
|
|
35
|
+
path = Pathname.new(File.join(ENV['XDG_RUNTIME_DIR'] || Dir.tmpdir, "spring"))
|
|
36
36
|
FileUtils.mkdir_p(path) unless path.exist?
|
|
37
37
|
path
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
def application_id
|
|
41
|
-
Digest::MD5.hexdigest(project_root.to_s)
|
|
41
|
+
Digest::MD5.hexdigest(RUBY_VERSION + project_root.to_s)
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
def socket_path
|
data/lib/spring/server.rb
CHANGED