nrispring 2.1.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 83d31d75e73dccb2153d0073ab8da0fb551faef6a6b797d72ce9e3fa9b7fdf83
4
+ data.tar.gz: 713ac969e8934a20a4d20b12c4a369f955adcfa2f5595b41999fb222313c6770
5
+ SHA512:
6
+ metadata.gz: c8bdaa6e155ba3c19c5d351618ba5511974e4d040660cf4a0a28f33f5090447f01c0b657928f1dd144c5588fc70ef3c263b69fd4daa880661cdae83ab287cbb4
7
+ data.tar.gz: 937affb23ae18469aff71dc8e0a70830a76cf355a6853f1e9e935873012d8d85587a7265a328f92de43b630ede6a4639c96a9528899835dd7cdada7de5f63a31
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012-2017 Jon Leighton
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,419 @@
1
+ # Spring
2
+
3
+ [![Build Status](https://travis-ci.org/rails/spring.svg?branch=master)](https://travis-ci.org/rails/spring)
4
+ [![Gem Version](https://badge.fury.io/rb/spring.svg)](http://badge.fury.io/rb/spring)
5
+
6
+ Spring is a Rails application preloader. It speeds up development by
7
+ keeping your application running in the background so you don't need to
8
+ boot it every time you run a test, rake task or migration.
9
+
10
+ ## Features
11
+
12
+ * Totally automatic; no need to explicitly start and stop the background process
13
+ * Reloads your application code on each run
14
+ * Restarts your application when configs / initializers / gem
15
+ dependencies are changed
16
+
17
+ ## Compatibility
18
+
19
+ * Ruby versions: MRI 2.4, MRI 2.5, MRI 2.6
20
+ * Rails versions: 4.2, 5.0, 5.1, 5.2, 6.0 (Spring is installed by default when you do
21
+ `rails new` to generate your application)
22
+
23
+ Spring makes extensive use of `Process.fork`, so won't be able to
24
+ provide a speed up on platforms which don't support forking (Windows, JRuby).
25
+
26
+ ## Walkthrough
27
+
28
+ ### Setup
29
+
30
+ Add Spring to your Gemfile:
31
+
32
+ ``` ruby
33
+ gem "spring", group: :development
34
+ ```
35
+
36
+ (Note: using `gem "spring", git: "..."` *won't* work and is not a
37
+ supported way of using Spring.)
38
+
39
+ It's recommended to 'springify' the executables in your `bin/`
40
+ directory:
41
+
42
+ ```
43
+ $ bundle install
44
+ $ bundle exec spring binstub --all
45
+ ```
46
+
47
+ This generates a `bin/spring` executable, and inserts a small snippet of
48
+ code into relevant existing executables. The snippet looks like this:
49
+
50
+ ``` ruby
51
+ begin
52
+ load File.expand_path('../spring', __FILE__)
53
+ rescue LoadError
54
+ end
55
+ ```
56
+
57
+ On platforms where Spring is installed and supported, this snippet
58
+ hooks Spring into the execution of commands. In other cases, the snippet
59
+ will just be silently ignored and the lines after it will be executed as
60
+ normal.
61
+
62
+ If you don't want to prefix every command you type with `bin/`, you
63
+ can [use direnv](https://github.com/direnv/direnv#the-stdlib) to
64
+ automatically add `./bin` to your `PATH` when you `cd` into your application.
65
+ Simply create an `.envrc` file with the command `PATH_add bin` in your
66
+ Rails directory.
67
+
68
+ ### Usage
69
+
70
+ For this walkthrough I've generated a new Rails application, and run
71
+ `rails generate scaffold post name:string`.
72
+
73
+ Let's run a test:
74
+
75
+ ```
76
+ $ time bin/rake test test/controllers/posts_controller_test.rb
77
+ Running via Spring preloader in process 2734
78
+ Run options:
79
+
80
+ # Running tests:
81
+
82
+ .......
83
+
84
+ Finished tests in 0.127245s, 55.0121 tests/s, 78.5887 assertions/s.
85
+
86
+ 7 tests, 10 assertions, 0 failures, 0 errors, 0 skips
87
+
88
+ real 0m2.165s
89
+ user 0m0.281s
90
+ sys 0m0.066s
91
+ ```
92
+
93
+ That wasn't particularly fast because it was the first run, so Spring
94
+ had to boot the application. It's now running:
95
+
96
+ ```
97
+ $ bin/spring status
98
+ Spring is running:
99
+
100
+ 26150 spring server | spring-demo-app | started 3 secs ago
101
+ 26155 spring app | spring-demo-app | started 3 secs ago | test mode
102
+ ```
103
+
104
+ The next run is faster:
105
+
106
+ ```
107
+ $ time bin/rake test test/controllers/posts_controller_test.rb
108
+ Running via Spring preloader in process 8352
109
+ Run options:
110
+
111
+ # Running tests:
112
+
113
+ .......
114
+
115
+ Finished tests in 0.176896s, 39.5714 tests/s, 56.5305 assertions/s.
116
+
117
+ 7 tests, 10 assertions, 0 failures, 0 errors, 0 skips
118
+
119
+ real 0m0.610s
120
+ user 0m0.276s
121
+ sys 0m0.059s
122
+ ```
123
+
124
+ If we edit any of the application files, or test files, the changes will
125
+ be picked up on the next run without the background process having to
126
+ restart. This works in exactly the same way as the code reloading
127
+ which allows you to refresh your browser and instantly see changes during
128
+ development.
129
+
130
+ But if we edit any of the files which were used to start the application
131
+ (configs, initializers, your gemfile), the application needs to be fully
132
+ restarted. This happens automatically.
133
+
134
+ Let's "edit" `config/application.rb`:
135
+
136
+ ```
137
+ $ touch config/application.rb
138
+ $ bin/spring status
139
+ Spring is running:
140
+
141
+ 26150 spring server | spring-demo-app | started 36 secs ago
142
+ 26556 spring app | spring-demo-app | started 1 sec ago | test mode
143
+ ```
144
+
145
+ The application detected that `config/application.rb` changed and
146
+ automatically restarted itself.
147
+
148
+ If we run a command that uses a different environment, then that
149
+ environment gets booted up:
150
+
151
+ ```
152
+ $ bin/rake routes
153
+ Running via Spring preloader in process 2363
154
+ posts GET /posts(.:format) posts#index
155
+ POST /posts(.:format) posts#create
156
+ new_post GET /posts/new(.:format) posts#new
157
+ edit_post GET /posts/:id/edit(.:format) posts#edit
158
+ post GET /posts/:id(.:format) posts#show
159
+ PUT /posts/:id(.:format) posts#update
160
+ DELETE /posts/:id(.:format) posts#destroy
161
+
162
+ $ bin/spring status
163
+ Spring is running:
164
+
165
+ 26150 spring server | spring-demo-app | started 1 min ago
166
+ 26556 spring app | spring-demo-app | started 42 secs ago | test mode
167
+ 26707 spring app | spring-demo-app | started 2 secs ago | development mode
168
+ ```
169
+
170
+ There's no need to "shut down" Spring. This will happen automatically
171
+ when you close your terminal. However if you do want to do a manual shut
172
+ down, use the `stop` command:
173
+
174
+ ```
175
+ $ bin/spring stop
176
+ Spring stopped.
177
+ ```
178
+
179
+ From within your code, you can check whether Spring is active with `if defined?(Spring)`.
180
+
181
+ ### Removal
182
+
183
+ To remove Spring:
184
+
185
+ * 'Unspring' your bin/ executables: `bin/spring binstub --remove --all`
186
+ * Remove spring from your Gemfile
187
+
188
+ ### Deployment
189
+
190
+ You must not install Spring on your production environment. To prevent it from
191
+ being installed, provide the `--without development test` argument to the
192
+ `bundle install` command which is used to install gems on your production
193
+ machines:
194
+
195
+ ```
196
+ $ bundle install --without development test
197
+ ```
198
+
199
+ ## Commands
200
+
201
+ ### `rake`
202
+
203
+ Runs a rake task. Rake tasks run in the `development` environment by
204
+ default. You can change this on the fly by using the `RAILS_ENV`
205
+ environment variable. The environment is also configurable with the
206
+ `Spring::Commands::Rake.environment_matchers` hash. This has sensible
207
+ defaults, but if you need to match a specific task to a specific
208
+ environment, you'd do it like this:
209
+
210
+ ``` ruby
211
+ Spring::Commands::Rake.environment_matchers["perf_test"] = "test"
212
+ Spring::Commands::Rake.environment_matchers[/^perf/] = "test"
213
+
214
+ # To change the environment when you run `rake` with no arguments
215
+ Spring::Commands::Rake.environment_matchers[:default] = "development"
216
+ ```
217
+
218
+ ### `rails console`, `rails generate`, `rails runner`
219
+
220
+ These execute the rails command you already know and love. If you run
221
+ a different sub command (e.g. `rails server`) then Spring will automatically
222
+ pass it through to the underlying `rails` executable (without the
223
+ speed-up).
224
+
225
+ ### Additional commands
226
+
227
+ You can add these to your Gemfile for additional commands:
228
+
229
+ * [spring-commands-rspec](https://github.com/jonleighton/spring-commands-rspec)
230
+ * [spring-commands-cucumber](https://github.com/jonleighton/spring-commands-cucumber)
231
+ * [spring-commands-spinach](https://github.com/jvanbaarsen/spring-commands-spinach)
232
+ * [spring-commands-testunit](https://github.com/jonleighton/spring-commands-testunit) - useful for
233
+ running `Test::Unit` tests on Rails 3, since only Rails 4 allows you
234
+ to use `rake test path/to/test` to run a particular test/directory.
235
+ * [spring-commands-parallel-tests](https://github.com/DocSpring/spring-commands-parallel-tests) - Adds the `parallel_*` commands from [`parallel_tests`](https://github.com/grosser/parallel_tests).
236
+ * [spring-commands-teaspoon](https://github.com/alejandrobabio/spring-commands-teaspoon.git)
237
+ * [spring-commands-m](https://github.com/gabrieljoelc/spring-commands-m.git)
238
+ * [spring-commands-rubocop](https://github.com/p0deje/spring-commands-rubocop)
239
+ * [spring-commands-rackup](https://github.com/wintersolutions/spring-commands-rackup)
240
+ * [spring-commands-rack-console](https://github.com/wintersolutions/spring-commands-rack-console)
241
+
242
+ ## Use without adding to bundle
243
+
244
+ If you don't want Spring-related code checked into your source
245
+ repository, it's possible to use Spring without adding to your Gemfile.
246
+ However, using Spring binstubs without adding Spring to the Gemfile is not
247
+ supported.
248
+
249
+ To use Spring like this, do a `gem install spring` and then prefix
250
+ commands with `spring`. For example, rather than running `bin/rake -T`,
251
+ you'd run `spring rake -T`.
252
+
253
+ ## Temporarily disabling Spring
254
+
255
+ If you're using Spring binstubs, but temporarily don't want commands to
256
+ run through Spring, set the `DISABLE_SPRING` environment variable.
257
+
258
+ ## Class reloading
259
+
260
+ Spring uses Rails' class reloading mechanism
261
+ (`ActiveSupport::Dependencies`) to keep your code up to date between
262
+ test runs. This is the same mechanism which allows you to see changes
263
+ during development when you refresh the page. However, you may never
264
+ have used this mechanism with your `test` environment before, and this
265
+ can cause problems.
266
+
267
+ It's important to realise that code reloading means that the constants
268
+ in your application are *different objects* after files have changed:
269
+
270
+ ```
271
+ $ bin/rails runner 'puts User.object_id'
272
+ 70127987886040
273
+ $ touch app/models/user.rb
274
+ $ bin/rails runner 'puts User.object_id'
275
+ 70127976764620
276
+ ```
277
+
278
+ Suppose you have an initializer `config/initializers/save_user_class.rb`
279
+ like so:
280
+
281
+ ``` ruby
282
+ USER_CLASS = User
283
+ ```
284
+
285
+ This saves off the *first* version of the `User` class, which will not
286
+ be the same object as `User` after the code has been reloaded:
287
+
288
+ ```
289
+ $ bin/rails runner 'puts User == USER_CLASS'
290
+ true
291
+ $ touch app/models/user.rb
292
+ $ bin/rails runner 'puts User == USER_CLASS'
293
+ false
294
+ ```
295
+
296
+ So to avoid this problem, don't save off references to application
297
+ constants in your initialization code.
298
+
299
+ ## Using Spring with a containerized development environment
300
+
301
+ As of Spring 1.7, there is some support for doing this. See [this
302
+ example
303
+ repository](https://github.com/jonleighton/spring-docker-example) for
304
+ information about how to do it with [Docker](https://www.docker.com/).
305
+
306
+ ## Configuration
307
+
308
+ Spring will read `~/.spring.rb` and `config/spring.rb` for custom
309
+ settings. Note that `~/.spring.rb` is loaded *before* bundler, but
310
+ `config/spring.rb` is loaded *after* bundler. So if you have any
311
+ `spring-commands-*` gems installed that you want to be available in all
312
+ projects without having to be added to the project's Gemfile, require
313
+ them in your `~/.spring.rb`.
314
+
315
+ `config/spring_client.rb` is also loaded before bundler and before a
316
+ server process is started, it can be used to add new top-level commands.
317
+
318
+ ### Application root
319
+
320
+ Spring must know how to find your Rails application. If you have a
321
+ normal app everything works out of the box. If you are working on a
322
+ project with a special setup (an engine for example), you must tell
323
+ Spring where your app is located:
324
+
325
+ ```ruby
326
+ Spring.application_root = './test/dummy'
327
+ ```
328
+
329
+ ### Running code before forking
330
+
331
+ There is no `Spring.before_fork` callback. To run something before the
332
+ fork, you can place it in `~/.spring.rb` or `config/spring.rb` or in any of the files
333
+ which get run when your application initializes, such as
334
+ `config/application.rb`, `config/environments/*.rb` or
335
+ `config/initializers/*.rb`.
336
+
337
+ ### Running code after forking
338
+
339
+ You might want to run code after Spring forked off the process but
340
+ before the actual command is run. You might want to use an
341
+ `after_fork` callback if you have to connect to an external service,
342
+ do some general cleanup or set up dynamic configuration.
343
+
344
+ ```ruby
345
+ Spring.after_fork do
346
+ # run arbitrary code
347
+ end
348
+ ```
349
+
350
+ If you want to register multiple callbacks you can simply call
351
+ `Spring.after_fork` multiple times with different blocks.
352
+
353
+ ### Watching files and directories
354
+
355
+ Spring will automatically detect file changes to any file loaded when the server
356
+ boots. Changes will cause the affected environments to be restarted.
357
+
358
+ If there are additional files or directories which should trigger an
359
+ application restart, you can specify them with `Spring.watch`:
360
+
361
+ ```ruby
362
+ Spring.watch "config/some_config_file.yml"
363
+ ```
364
+
365
+ By default Spring polls the filesystem for changes once every 0.2 seconds. This
366
+ method requires zero configuration, but if you find that it's using too
367
+ much CPU, then you can use event-based file system listening by
368
+ installing the
369
+ [spring-watcher-listen](https://github.com/jonleighton/spring-watcher-listen)
370
+ gem.
371
+
372
+ ### Quiet output
373
+
374
+ To disable the "Running via Spring preloader" message which is shown each time
375
+ a command runs:
376
+
377
+ ``` ruby
378
+ Spring.quiet = true
379
+ ```
380
+
381
+ ### Environment variables
382
+
383
+ The following environment variables are used by Spring:
384
+
385
+ * `DISABLE_SPRING` - If set, Spring will be bypassed and your
386
+ application will boot in a foreground process
387
+ * `SPRING_LOG` - The path to a file which Spring will write log messages
388
+ to.
389
+ * `SPRING_TMP_PATH` - The directory where Spring should write its temporary
390
+ files (a pidfile and a socket). By default we use the
391
+ `XDG_RUNTIME_DIR` environment variable, or else `Dir.tmpdir`, and then
392
+ create a directory in that named `spring-$UID`. We don't use your
393
+ Rails application's `tmp/` directory because that may be on a
394
+ filesystem which doesn't support UNIX sockets.
395
+ * `SPRING_APPLICATION_ID` - Used to identify distinct Rails
396
+ applications. By default it is an MD5 hash of the current
397
+ `RUBY_VERSION`, and the path to your Rails project root.
398
+ * `SPRING_SOCKET` - The path which should be used for the UNIX socket
399
+ which Spring uses to communicate with the long-running Spring server
400
+ process. By default this is `SPRING_TMP_PATH/SPRING_APPLICATION_ID`.
401
+ * `SPRING_PIDFILE` - The path which should be used to store the pid of
402
+ the long-running Spring server process. By default this is related to
403
+ the socket path; if the socket path is `/foo/bar/spring.sock` the
404
+ pidfile will be `/foo/bar/spring.pid`.
405
+ * `SPRING_SERVER_COMMAND` - The command to run to start up the Spring
406
+ server when it is not already running. Defaults to `spring _[version]_
407
+ server --background`.
408
+
409
+ ## Troubleshooting
410
+
411
+ If you want to get more information about what Spring is doing, you can
412
+ run Spring explicitly in a separate terminal:
413
+
414
+ ```
415
+ $ spring server
416
+ ```
417
+
418
+ Logging output will be printed to stdout. You can also send log output
419
+ to a file with the `SPRING_LOG` environment variable.
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env ruby
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
+
19
+ if defined?(Gem)
20
+ if Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.1.0")
21
+ warn "Warning: You're using Rubygems #{Gem::VERSION} with Spring. " \
22
+ "Upgrade to at least Rubygems 2.1.0 and run `gem pristine --all` for better " \
23
+ "startup performance."
24
+ else
25
+ stubs = Gem::Specification.stubs.grep(Gem::StubSpecification)
26
+
27
+ # stubbed? method added in https://github.com/rubygems/rubygems/pull/694
28
+ if Gem::Specification.stubs.first.respond_to?(:stubbed?)
29
+ unstubbed = stubs.reject(&:stubbed?)
30
+ else
31
+ unstubbed = stubs.reject { |s| s.send(:data).is_a?(Gem::StubSpecification::StubLine) }
32
+ end
33
+
34
+ # `gem pristine --all` ignores default gems. it doesn't really matter,
35
+ # as there are probably not many of them on the system.
36
+ unstubbed.reject!(&:default_gem?)
37
+
38
+ if unstubbed.any?
39
+ warn "Warning: Running `gem pristine --all` to regenerate your installed gemspecs " \
40
+ "(and deleting then reinstalling your bundle if you use bundle --path) " \
41
+ "will improve the startup performance of Spring."
42
+ end
43
+ end
44
+ end
45
+
46
+ lib = File.expand_path("../../lib", __FILE__)
47
+ $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib) # enable local development
48
+ require 'spring/client'
49
+ Spring::Client.run(ARGV)