spring 1.0.0 → 1.3.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 +6 -1
- data/CHANGELOG.md +81 -0
- data/CONTRIBUTING.md +52 -0
- data/Gemfile +0 -2
- data/README.md +137 -54
- data/Rakefile +1 -1
- data/bin/spring +17 -0
- data/lib/spring/application/boot.rb +18 -0
- data/lib/spring/application.rb +183 -76
- data/lib/spring/application_manager.rb +54 -40
- data/lib/spring/binstub.rb +13 -0
- data/lib/spring/boot.rb +8 -0
- data/lib/spring/client/binstub.rb +150 -39
- data/lib/spring/client/help.rb +4 -12
- data/lib/spring/client/rails.rb +2 -3
- data/lib/spring/client/run.rb +69 -11
- data/lib/spring/client/status.rb +2 -2
- data/lib/spring/client/stop.rb +6 -21
- data/lib/spring/client/version.rb +11 -0
- data/lib/spring/client.rb +8 -5
- data/lib/spring/command_wrapper.rb +82 -0
- data/lib/spring/commands/rails.rb +44 -13
- data/lib/spring/commands/rake.rb +0 -4
- data/lib/spring/commands.rb +14 -4
- data/lib/spring/configuration.rb +11 -2
- data/lib/spring/env.rb +36 -10
- data/lib/spring/server.rb +9 -35
- data/lib/spring/sid.rb +1 -1
- data/lib/spring/test/acceptance_test.rb +346 -0
- data/lib/spring/test/application.rb +217 -0
- 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 +18 -0
- data/lib/spring/version.rb +1 -1
- data/lib/spring/watcher/abstract.rb +7 -8
- data/lib/spring/watcher/polling.rb +2 -0
- data/lib/spring/watcher.rb +4 -8
- data/spring.gemspec +2 -2
- data/test/acceptance_test.rb +4 -0
- data/test/helper.rb +2 -2
- data/test/unit/client/version_test.rb +14 -0
- data/test/unit/commands_test.rb +23 -1
- data/test/unit/watcher_test.rb +2 -184
- metadata +30 -17
- data/lib/spring/watcher/listen.rb +0 -52
- data/test/acceptance/app_test.rb +0 -511
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cf0643d72425f9cc14e93423dd4f131aa42b143a
|
|
4
|
+
data.tar.gz: 224eb7729ea0b874659a2951fea96fbdc3bb4c8a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f31525f82a8f8daa814e08ab0fb0ca65047fe25652037421899e7e4da566f7bbefb8b95bd4920fe40827d275b000e5f9dce5f1ea031c64bd807ebbe1912503e8
|
|
7
|
+
data.tar.gz: 07594958b366487e7b5f88d96edb3efa1b5f1378de5b68b37ef711d149084116cfd421562061e985c7d12a90d22a72caa8f96480362ca95eba40ed6916a3fa42
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
|
@@ -2,6 +2,11 @@ language: ruby
|
|
|
2
2
|
rvm:
|
|
3
3
|
- 1.9.3
|
|
4
4
|
- 2.0.0
|
|
5
|
+
- 2.1.5
|
|
6
|
+
- 2.2.0
|
|
5
7
|
env:
|
|
6
|
-
- RAILS_VERSION="~> 3.2.0"
|
|
7
8
|
- RAILS_VERSION="~> 4.0.0"
|
|
9
|
+
- RAILS_VERSION="~> 4.1.0"
|
|
10
|
+
- RAILS_VERSION="~> 4.2.0"
|
|
11
|
+
before_script:
|
|
12
|
+
- travis_retry gem install rails --version "$RAILS_VERSION"
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,84 @@
|
|
|
1
|
+
## 1.3.0
|
|
2
|
+
|
|
3
|
+
* Automatically restart spring after new commands are added. This means
|
|
4
|
+
that you can add spring-commands-rspec to your Gemfile and then
|
|
5
|
+
immediately start using it, without having to run `spring stop`.
|
|
6
|
+
(Spring will effectively run `spring stop` for you.)
|
|
7
|
+
* Make app reloading work in apps which spew out lots of output on
|
|
8
|
+
startup (previously a buffer would fill up and cause the process to
|
|
9
|
+
hang). Issue #332.
|
|
10
|
+
* Make sure running `bin/spring` does not add an empty string to `Gem.path`.
|
|
11
|
+
Issues #297, #310.
|
|
12
|
+
* Fixed problem with `$0` including the command line args, which could
|
|
13
|
+
confuse commands which try to parse `$0`. This caused the
|
|
14
|
+
spring-commands-rspec to not work properly in some cases. Issue #369.
|
|
15
|
+
* Add OpenBSD compatibility for `spring status`. Issue #299.
|
|
16
|
+
* Rails 3.2 no longer officially supported (but it may continue to work)
|
|
17
|
+
|
|
18
|
+
## 1.2.0
|
|
19
|
+
|
|
20
|
+
* Accept -e and --environment options for `rails console`.
|
|
21
|
+
* Watch `config/secrets.yml` by default. #289 - @morgoth
|
|
22
|
+
* Change monkey-patched `Kernel.raise` from public to private (to match default Ruby behavior) #351 - @mattbrictson
|
|
23
|
+
* Let application_id also respect RUBY_VERSION for the use case of switching between Ruby versions for a given Rails app - @methodmissing
|
|
24
|
+
* Extract the 'listen' watcher to a separate `spring-watcher-listen`
|
|
25
|
+
gem. This allows it to be developed/maintained separately.
|
|
26
|
+
|
|
27
|
+
## 1.1.3
|
|
28
|
+
|
|
29
|
+
* The `rails runner` command no longer passes environment switches to
|
|
30
|
+
files which it runs. Issue #272.
|
|
31
|
+
* Various issues solved to do with termination / processes hanging around
|
|
32
|
+
longer than they should. Issue #290.
|
|
33
|
+
|
|
34
|
+
## 1.1.2
|
|
35
|
+
|
|
36
|
+
* Detect old binstubs generated with Spring 1.0 and exit with an error.
|
|
37
|
+
This prevents a situation where you can get stuck in an infinite loop
|
|
38
|
+
of spring invocations.
|
|
39
|
+
* Avoid `warning: already initialized constant APP_PATH` when running
|
|
40
|
+
rails commands that do not use spring (e.g. `bin/rails server` would
|
|
41
|
+
emit this when you ^C to exit)
|
|
42
|
+
* Fix `reload!` in rails console
|
|
43
|
+
* Don't connect/disconnect the database if there are no connections
|
|
44
|
+
configured. Issue #256.
|
|
45
|
+
|
|
46
|
+
## 1.1.1
|
|
47
|
+
|
|
48
|
+
* Fix `$0` so that it is no longer prefixed with "spring ", as doing
|
|
49
|
+
this cause issues with rspec when running just `rspec` with no
|
|
50
|
+
arguments.
|
|
51
|
+
* Ensure we're always connected to a tty when preloading the
|
|
52
|
+
application in the background, in order to avoid loading issues
|
|
53
|
+
with readline + libedit which affected pry-rails.
|
|
54
|
+
|
|
55
|
+
## 1.1.0
|
|
56
|
+
|
|
57
|
+
* A `bin/spring` binstub is now generated. This allows us to load spring
|
|
58
|
+
correctly if you have it installed locally with a `BUNDLE_PATH`, so
|
|
59
|
+
it's no longer necessary to install spring system-wide. We also
|
|
60
|
+
activate the correct version from your Gemfile.lock. Note that you
|
|
61
|
+
still can't have spring in your Gemfile as a git repository or local
|
|
62
|
+
path; it must be a proper gem.
|
|
63
|
+
* Various changes to how springified binstubs are implemented. Existing
|
|
64
|
+
binstubs will continue to work, but it's recommended to run `spring binstub`
|
|
65
|
+
again to upgrade them to the new format.
|
|
66
|
+
* `spring binstub --remove` option added for removing spring from
|
|
67
|
+
binstubs. This won't work unless you have upgraded your binstubs to
|
|
68
|
+
the new format.
|
|
69
|
+
* `config/database.yml` is watched
|
|
70
|
+
* Better application restarts - if you introduce an error, for example
|
|
71
|
+
by editing `config/application.rb`, spring will now continue to watch
|
|
72
|
+
your files and will immediately try to restart the application when
|
|
73
|
+
you edit `config/application.rb` again (hopefully to correct the error).
|
|
74
|
+
This means that by the time you come to run a command the application
|
|
75
|
+
may well already be running.
|
|
76
|
+
* Gemfile changes are now gracefully handled. Previously they would
|
|
77
|
+
cause spring to simply quit, meaning that you'd incur the full startup
|
|
78
|
+
penalty on the next run. Now spring doesn't quit, and will try to load
|
|
79
|
+
up your new bundle in the background.
|
|
80
|
+
* Fix support for using spring with Rails engines/plugins
|
|
81
|
+
|
|
1
82
|
## 1.0.0
|
|
2
83
|
|
|
3
84
|
* Enterprise ready secret sauce added
|
data/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
|
|
6
|
+
# Contributing guide
|
|
7
|
+
|
|
8
|
+
## Getting set up
|
|
9
|
+
|
|
10
|
+
Check out the code and run `bundle install` as usual.
|
|
11
|
+
|
|
12
|
+
## Running tests
|
|
13
|
+
|
|
14
|
+
Running `rake` will run all tests. There are both unit tests and
|
|
15
|
+
acceptance tests. You can run them individually with `rake test:unit` or
|
|
16
|
+
`rake test:acceptance`.
|
|
17
|
+
|
|
18
|
+
If one doesn't already exist, the acceptance tests will generate a dummy
|
|
19
|
+
Rails app in `test/apps/`. On each test run, the dummy app is copied to
|
|
20
|
+
`test/apps/tmp/` so that any changes won't affect the pre-generated app
|
|
21
|
+
(this saves us having to regenerate the app on each run).
|
|
22
|
+
|
|
23
|
+
If tests are failing and you don't know why, it might be that the
|
|
24
|
+
pre-generated app has become inconsistent in some way. In that case the
|
|
25
|
+
best solution is to purge it with `rm -rf test/apps/*` and then run the
|
|
26
|
+
acceptance tests again, which will generate a new app.
|
|
27
|
+
|
|
28
|
+
## Testing different Rails versions
|
|
29
|
+
|
|
30
|
+
You can set the `RAILS_VERSION` environment variable:
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
$ RAILS_VERSION="~> 3.2.0" rake test:acceptance
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
The apps in `test/apps` will be named based on the rails version and the
|
|
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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# Spring
|
|
2
2
|
|
|
3
|
-
[](https://travis-ci.org/rails/spring)
|
|
4
|
+
[](http://badge.fury.io/rb/spring)
|
|
4
5
|
|
|
5
6
|
Spring is a Rails application preloader. It speeds up development by
|
|
6
7
|
keeping your application running in the background so you don't need to
|
|
@@ -15,24 +16,55 @@ boot it every time you run a test, rake task or migration.
|
|
|
15
16
|
|
|
16
17
|
## Compatibility
|
|
17
18
|
|
|
18
|
-
* Ruby versions: MRI 1.9.3, MRI 2.0.
|
|
19
|
-
* Rails versions: 3.2, 4.0
|
|
19
|
+
* Ruby versions: MRI 1.9.3, MRI 2.0, MRI 2.1
|
|
20
|
+
* Rails versions: 3.2, 4.0 (in Rails 4.1 and up Spring is included by default)
|
|
20
21
|
|
|
21
|
-
Spring makes extensive use of `Process
|
|
22
|
+
Spring makes extensive use of `Process.fork`, so won't be able to
|
|
22
23
|
provide a speed up on platforms which don't support forking (Windows, JRuby).
|
|
23
24
|
|
|
24
25
|
## Walkthrough
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
### Setup
|
|
28
|
+
|
|
29
|
+
Add spring to your Gemfile:
|
|
30
|
+
|
|
31
|
+
``` ruby
|
|
32
|
+
gem "spring", group: :development
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
(Note: using `gem "spring", git: "..."` *won't* work and is not a
|
|
36
|
+
supported way of using spring.)
|
|
37
|
+
|
|
38
|
+
It's recommended to 'springify' the executables in your `bin/`
|
|
39
|
+
directory:
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
$ bundle install
|
|
43
|
+
$ bundle exec spring binstub --all
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
This generates a `bin/spring` executable, and inserts a small snippet of
|
|
47
|
+
code into relevant existing executables. The snippet looks like this:
|
|
27
48
|
|
|
28
49
|
``` ruby
|
|
29
|
-
|
|
30
|
-
|
|
50
|
+
begin
|
|
51
|
+
load File.expand_path("../spring", __FILE__)
|
|
52
|
+
rescue LoadError
|
|
31
53
|
end
|
|
32
54
|
```
|
|
33
55
|
|
|
34
|
-
|
|
35
|
-
|
|
56
|
+
On platforms where spring is installed and supported, this snippet
|
|
57
|
+
hooks spring into the execution of commands. In other cases, the snippet
|
|
58
|
+
will just be silently ignored and the lines after it will be executed as
|
|
59
|
+
normal.
|
|
60
|
+
|
|
61
|
+
If you don't want to prefix every command you type with `bin/`, you
|
|
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.
|
|
66
|
+
|
|
67
|
+
### Usage
|
|
36
68
|
|
|
37
69
|
For this walkthrough I've generated a new Rails application, and run
|
|
38
70
|
`rails generate scaffold posts name:string`.
|
|
@@ -40,7 +72,7 @@ For this walkthrough I've generated a new Rails application, and run
|
|
|
40
72
|
Let's run a test:
|
|
41
73
|
|
|
42
74
|
```
|
|
43
|
-
$ time
|
|
75
|
+
$ time bin/rake test test/functional/posts_controller_test.rb
|
|
44
76
|
Run options:
|
|
45
77
|
|
|
46
78
|
# Running tests:
|
|
@@ -60,7 +92,7 @@ That wasn't particularly fast because it was the first run, so spring
|
|
|
60
92
|
had to boot the application. It's now running:
|
|
61
93
|
|
|
62
94
|
```
|
|
63
|
-
$ spring status
|
|
95
|
+
$ bin/spring status
|
|
64
96
|
Spring is running:
|
|
65
97
|
|
|
66
98
|
26150 spring server | spring-demo-app | started 3 secs ago
|
|
@@ -70,7 +102,7 @@ Spring is running:
|
|
|
70
102
|
The next run is faster:
|
|
71
103
|
|
|
72
104
|
```
|
|
73
|
-
$ time
|
|
105
|
+
$ time bin/rake test test/functional/posts_controller_test.rb
|
|
74
106
|
Run options:
|
|
75
107
|
|
|
76
108
|
# Running tests:
|
|
@@ -86,20 +118,6 @@ user 0m0.276s
|
|
|
86
118
|
sys 0m0.059s
|
|
87
119
|
```
|
|
88
120
|
|
|
89
|
-
Writing `spring` before every command gets a bit tedious. Spring binstubs solve this:
|
|
90
|
-
|
|
91
|
-
```
|
|
92
|
-
$ spring binstub rake rails
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
This will generate `bin/rake` and `bin/rails`. They
|
|
96
|
-
replace any binstubs that you might already have in your `bin/`
|
|
97
|
-
directory. Check them in to source control.
|
|
98
|
-
|
|
99
|
-
If you don't want to prefix every command you type with `bin/`, you
|
|
100
|
-
can [use direnv](https://github.com/zimbatm/direnv) to automatically add
|
|
101
|
-
`./bin` to your `PATH` when you `cd` into your application.
|
|
102
|
-
|
|
103
121
|
If we edit any of the application files, or test files, the changes will
|
|
104
122
|
be picked up on the next run without the background process having to
|
|
105
123
|
restart. This works in exactly the same way as the code reloading
|
|
@@ -114,7 +132,7 @@ Let's "edit" `config/application.rb`:
|
|
|
114
132
|
|
|
115
133
|
```
|
|
116
134
|
$ touch config/application.rb
|
|
117
|
-
$ spring status
|
|
135
|
+
$ bin/spring status
|
|
118
136
|
Spring is running:
|
|
119
137
|
|
|
120
138
|
26150 spring server | spring-demo-app | started 36 secs ago
|
|
@@ -137,7 +155,7 @@ edit_post GET /posts/:id/edit(.:format) posts#edit
|
|
|
137
155
|
PUT /posts/:id(.:format) posts#update
|
|
138
156
|
DELETE /posts/:id(.:format) posts#destroy
|
|
139
157
|
|
|
140
|
-
$ spring status
|
|
158
|
+
$ bin/spring status
|
|
141
159
|
Spring is running:
|
|
142
160
|
|
|
143
161
|
26150 spring server | spring-demo-app | started 1 min ago
|
|
@@ -150,25 +168,29 @@ when you close your terminal. However if you do want to do a manual shut
|
|
|
150
168
|
down, use the `stop` command:
|
|
151
169
|
|
|
152
170
|
```
|
|
153
|
-
$ spring stop
|
|
171
|
+
$ bin/spring stop
|
|
154
172
|
Spring stopped.
|
|
155
173
|
```
|
|
156
174
|
|
|
157
|
-
|
|
175
|
+
### Removal
|
|
158
176
|
|
|
159
|
-
|
|
177
|
+
To remove spring:
|
|
160
178
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
for examples.
|
|
179
|
+
* 'Unspring' your bin/ executables: `bin/spring binstub --remove --all`
|
|
180
|
+
* Remove spring from your Gemfile
|
|
164
181
|
|
|
165
|
-
|
|
182
|
+
### Deployment
|
|
166
183
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
+
|
|
193
|
+
## Commands
|
|
172
194
|
|
|
173
195
|
### `rake`
|
|
174
196
|
|
|
@@ -194,6 +216,75 @@ a different sub command (e.g. `rails server`) then spring will automatically
|
|
|
194
216
|
pass it through to the underlying `rails` executable (without the
|
|
195
217
|
speed-up).
|
|
196
218
|
|
|
219
|
+
### Additional commands
|
|
220
|
+
|
|
221
|
+
You can add these to your Gemfile for additional commands:
|
|
222
|
+
|
|
223
|
+
* [spring-commands-rspec](https://github.com/jonleighton/spring-commands-rspec)
|
|
224
|
+
* [spring-commands-cucumber](https://github.com/jonleighton/spring-commands-cucumber)
|
|
225
|
+
* [spring-commands-spinach](https://github.com/jvanbaarsen/spring-commands-spinach)
|
|
226
|
+
* [spring-commands-testunit](https://github.com/jonleighton/spring-commands-testunit) - useful for
|
|
227
|
+
running `Test::Unit` tests on Rails 3, since only Rails 4 allows you
|
|
228
|
+
to use `rake test path/to/test` to run a particular test/directory.
|
|
229
|
+
* [spring-commands-teaspoon](https://github.com/alejandrobabio/spring-commands-teaspoon.git)
|
|
230
|
+
|
|
231
|
+
## Use without adding to bundle
|
|
232
|
+
|
|
233
|
+
If you don't want spring-related code checked into your source
|
|
234
|
+
repository, it's possible to use spring without adding to your Gemfile.
|
|
235
|
+
However, using spring binstubs without adding spring to the Gemfile is not
|
|
236
|
+
supported.
|
|
237
|
+
|
|
238
|
+
To use spring like this, do a `gem install spring` and then prefix
|
|
239
|
+
commands with `spring`. For example, rather than running `bin/rake -T`,
|
|
240
|
+
you'd run `spring rake -T`.
|
|
241
|
+
|
|
242
|
+
## Temporarily disabling Spring
|
|
243
|
+
|
|
244
|
+
If you're using Spring binstubs, but temporarily don't want commands to
|
|
245
|
+
run through Spring, set the `DISABLE_SPRING` environment variable.
|
|
246
|
+
|
|
247
|
+
## Class reloading
|
|
248
|
+
|
|
249
|
+
Spring uses Rails' class reloading mechanism
|
|
250
|
+
(`ActiveSupport::Dependencies`) to keep your code up to date between
|
|
251
|
+
test runs. This is the same mechanism which allows you to see changes
|
|
252
|
+
during development when you refresh the page. However, you may never
|
|
253
|
+
have used this mechanism with your `test` environment before, and this
|
|
254
|
+
can cause problems.
|
|
255
|
+
|
|
256
|
+
It's important to realise that code reloading means that the constants
|
|
257
|
+
in your application are *different objects* after files have changed:
|
|
258
|
+
|
|
259
|
+
```
|
|
260
|
+
$ bin/rails runner 'puts User.object_id'
|
|
261
|
+
70127987886040
|
|
262
|
+
$ touch app/models/user.rb
|
|
263
|
+
$ bin/rails runner 'puts User.object_id'
|
|
264
|
+
70127976764620
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
Suppose you have an initializer `config/initializers/save_user_class.rb`
|
|
268
|
+
like so:
|
|
269
|
+
|
|
270
|
+
``` ruby
|
|
271
|
+
USER_CLASS = User
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
This saves off the *first* version of the `User` class, which will not
|
|
275
|
+
be the same object as `User` after the code has been reloaded:
|
|
276
|
+
|
|
277
|
+
```
|
|
278
|
+
$ bin/rails runner 'puts User == USER_CLASS'
|
|
279
|
+
true
|
|
280
|
+
$ touch app/models/user.rb
|
|
281
|
+
$ bin/rails runner 'puts User == USER_CLASS'
|
|
282
|
+
false
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
So to avoid this problem, don't save off references to application
|
|
286
|
+
constants in your initialization code.
|
|
287
|
+
|
|
197
288
|
## Configuration
|
|
198
289
|
|
|
199
290
|
Spring will read `~/.spring.rb` and `config/spring.rb` for custom
|
|
@@ -218,15 +309,10 @@ Spring.application_root = './test/dummy'
|
|
|
218
309
|
|
|
219
310
|
There is no `Spring.before_fork` callback. To run something before the
|
|
220
311
|
fork, you can place it in `~/.spring.rb` or `config/spring.rb` or in any of the files
|
|
221
|
-
which get run when your application
|
|
312
|
+
which get run when your application initializes, such as
|
|
222
313
|
`config/application.rb`, `config/environments/*.rb` or
|
|
223
314
|
`config/initializers/*.rb`.
|
|
224
315
|
|
|
225
|
-
For example, if loading your test helper is slow, you might like to
|
|
226
|
-
preload it to speed up your test runs. To do this you could put a
|
|
227
|
-
`require Rails.root.join("test/helper")` in
|
|
228
|
-
`config/environments/test.rb`.
|
|
229
|
-
|
|
230
316
|
### Running code after forking
|
|
231
317
|
|
|
232
318
|
You might want to run code after Spring forked off the process but
|
|
@@ -252,18 +338,15 @@ If there are additional files or directories which should trigger an
|
|
|
252
338
|
application restart, you can specify them with `Spring.watch`:
|
|
253
339
|
|
|
254
340
|
```ruby
|
|
255
|
-
Spring.watch "
|
|
341
|
+
Spring.watch "config/some_config_file.yml"
|
|
256
342
|
```
|
|
257
343
|
|
|
258
344
|
By default Spring polls the filesystem for changes once every 0.2 seconds. This
|
|
259
345
|
method requires zero configuration, but if you find that it's using too
|
|
260
|
-
much CPU, then you can
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
```
|
|
265
|
-
|
|
266
|
-
You may need to add the [`listen` gem](https://github.com/guard/listen) to your `Gemfile`.
|
|
346
|
+
much CPU, then you can use event-based file system listening by
|
|
347
|
+
installing the
|
|
348
|
+
[spring-watcher-listen](https://github.com/jonleighton/spring-watcher-listen)
|
|
349
|
+
gem.
|
|
267
350
|
|
|
268
351
|
## Troubleshooting
|
|
269
352
|
|
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. " \
|
|
@@ -21,6 +37,7 @@ if defined?(Gem)
|
|
|
21
37
|
|
|
22
38
|
if unstubbed.any?
|
|
23
39
|
warn "Warning: Running `gem pristine --all` to regenerate your installed gemspecs " \
|
|
40
|
+
"(and deleting then reinstalling your bundle if you use bundle --path) " \
|
|
24
41
|
"will improve the startup performance of Spring."
|
|
25
42
|
end
|
|
26
43
|
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# This is necessary for the terminal to work correctly when we reopen stdin.
|
|
2
|
+
Process.setsid
|
|
3
|
+
|
|
4
|
+
require "spring/application"
|
|
5
|
+
|
|
6
|
+
app = Spring::Application.new(
|
|
7
|
+
UNIXSocket.for_fd(3),
|
|
8
|
+
Spring::JSON.load(ENV.delete("SPRING_ORIGINAL_ENV").dup)
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
Signal.trap("TERM") { app.terminate }
|
|
12
|
+
|
|
13
|
+
Spring::ProcessTitleUpdater.run { |distance|
|
|
14
|
+
"spring app | #{app.app_name} | started #{distance} ago | #{app.app_env} mode"
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
app.eager_preload if ENV.delete("SPRING_PRELOAD") == "1"
|
|
18
|
+
app.run
|