spring 1.1.3 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6828395a6b2b9a2d02ec15c9baba9305f36dbec9
4
- data.tar.gz: 62af73ac2056ca5a62ed440c0e9220f115c82830
3
+ metadata.gz: cf0643d72425f9cc14e93423dd4f131aa42b143a
4
+ data.tar.gz: 224eb7729ea0b874659a2951fea96fbdc3bb4c8a
5
5
  SHA512:
6
- metadata.gz: 73d982d8d66de05071338ea45fd59b042c5f05a5cb2eb32a10143777e0ec8e120a8b0ecd6d02e18570ee8515b4c18079dc67f12a74c5523f5f6586e93ba3b54c
7
- data.tar.gz: 54cc11c7135f91337199ee65d4062516ceec762c87f943bdb823b58b646e10d16d48cc5248b33cabcf68b517319fb7397c469e1d3ce3f75a378152cca30256db
6
+ metadata.gz: f31525f82a8f8daa814e08ab0fb0ca65047fe25652037421899e7e4da566f7bbefb8b95bd4920fe40827d275b000e5f9dce5f1ea031c64bd807ebbe1912503e8
7
+ data.tar.gz: 07594958b366487e7b5f88d96edb3efa1b5f1378de5b68b37ef711d149084116cfd421562061e985c7d12a90d22a72caa8f96480362ca95eba40ed6916a3fa42
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ spec/reports
16
16
  test/tmp
17
17
  test/version_tmp
18
18
  tmp
19
+ .ruby-version
data/.travis.yml CHANGED
@@ -2,10 +2,11 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
- - 2.1.2
5
+ - 2.1.5
6
+ - 2.2.0
6
7
  env:
7
- - RAILS_VERSION="~> 3.2.0"
8
8
  - RAILS_VERSION="~> 4.0.0"
9
9
  - RAILS_VERSION="~> 4.1.0"
10
+ - RAILS_VERSION="~> 4.2.0"
10
11
  before_script:
11
12
  - travis_retry gem install rails --version "$RAILS_VERSION"
data/CHANGELOG.md CHANGED
@@ -1,3 +1,29 @@
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
+
1
27
  ## 1.1.3
2
28
 
3
29
  * The `rails runner` command no longer passes environment switches to
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
data/Gemfile CHANGED
@@ -2,5 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in spring.gemspec
4
4
  gemspec
5
-
6
- gem 'listen', "~> 1.0", :require => false
data/README.md CHANGED
@@ -1,14 +1,12 @@
1
1
  # Spring
2
2
 
3
- [![Build Status](https://travis-ci.org/rails/spring.png?branch=master)](https://travis-ci.org/rails/spring)
4
- [![Gem Version](https://badge.fury.io/rb/spring.png)](http://badge.fury.io/rb/spring)
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
5
 
6
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
@@ -61,8 +59,10 @@ will just be silently ignored and the lines after it will be executed as
61
59
  normal.
62
60
 
63
61
  If you don't want to prefix every command you type with `bin/`, you
64
- can [use direnv](https://github.com/zimbatm/direnv) to automatically add
65
- `./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.
66
66
 
67
67
  ### Usage
68
68
 
@@ -179,6 +179,17 @@ To remove spring:
179
179
  * 'Unspring' your bin/ executables: `bin/spring binstub --remove --all`
180
180
  * Remove spring from your Gemfile
181
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
+
182
193
  ## Commands
183
194
 
184
195
  ### `rake`
@@ -207,8 +218,7 @@ speed-up).
207
218
 
208
219
  ### Additional commands
209
220
 
210
- You can add these to your Gemfile for additional commands (run `spring stop` afterwards
211
- to pick up the changes):
221
+ You can add these to your Gemfile for additional commands:
212
222
 
213
223
  * [spring-commands-rspec](https://github.com/jonleighton/spring-commands-rspec)
214
224
  * [spring-commands-cucumber](https://github.com/jonleighton/spring-commands-cucumber)
@@ -333,13 +343,10 @@ Spring.watch "config/some_config_file.yml"
333
343
 
334
344
  By default Spring polls the filesystem for changes once every 0.2 seconds. This
335
345
  method requires zero configuration, but if you find that it's using too
336
- much CPU, then you can turn on event-based file system listening:
337
-
338
- ```ruby
339
- Spring.watch_method = :listen
340
- ```
341
-
342
- 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.
343
350
 
344
351
  ## Troubleshooting
345
352
 
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ namespace :test do
10
10
 
11
11
  Rake::TestTask.new(:acceptance) do |t|
12
12
  t.libs << "test"
13
- t.test_files = FileList["test/acceptance/*_test.rb"]
13
+ t.test_files = FileList["test/acceptance_test.rb"]
14
14
  t.verbose = true
15
15
  end
16
16
 
@@ -108,6 +108,9 @@ module Spring
108
108
  if defined?(Rails) && Rails.application
109
109
  watcher.add Rails.application.paths["config/initializers"]
110
110
  watcher.add Rails.application.paths["config/database"]
111
+ if secrets_path = Rails.application.paths["config/secrets"]
112
+ watcher.add secrets_path
113
+ end
111
114
  end
112
115
  end
113
116
 
@@ -155,7 +158,7 @@ module Spring
155
158
  trap("TERM", "DEFAULT")
156
159
 
157
160
  ARGV.replace(args)
158
- $0 = command.process_title
161
+ $0 = command.exec_name
159
162
 
160
163
  # Delete all env vars which are unchanged from before spring started
161
164
  original_env.each { |k, v| ENV.delete k if ENV[k] == v }
@@ -267,6 +270,7 @@ module Spring
267
270
  end
268
271
  end
269
272
  end
273
+ private :raise
270
274
  end
271
275
  end
272
276
 
@@ -279,6 +283,7 @@ module Spring
279
283
  def with_pty
280
284
  PTY.open do |master, slave|
281
285
  [STDOUT, STDERR, STDIN].each { |s| s.reopen slave }
286
+ Thread.new { master.read }
282
287
  yield
283
288
  reset_streams
284
289
  end
@@ -36,9 +36,9 @@ 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
- ENV["GEM_HOME"] = ""
41
+ ENV["GEM_HOME"] = nil
42
42
  Gem.paths = ENV
43
43
 
44
44
  gem "spring", match[1]
@@ -21,7 +21,37 @@ module Spring
21
21
  end
22
22
 
23
23
  def call
24
- boot_server unless env.server_running?
24
+ if env.server_running?
25
+ warm_run
26
+ else
27
+ cold_run
28
+ end
29
+ rescue Errno::ECONNRESET
30
+ exit 1
31
+ ensure
32
+ server.close if @server
33
+ end
34
+
35
+ def warm_run
36
+ run
37
+ rescue CommandNotFound
38
+ require "spring/commands"
39
+
40
+ if Spring.command?(args.first)
41
+ # Command installed since spring started
42
+ stop_server
43
+ cold_run
44
+ else
45
+ raise
46
+ end
47
+ end
48
+
49
+ def cold_run
50
+ boot_server
51
+ run
52
+ end
53
+
54
+ def run
25
55
  verify_server_version
26
56
 
27
57
  application, client = UNIXSocket.pair
@@ -29,19 +59,16 @@ module Spring
29
59
  queue_signals
30
60
  connect_to_application(client)
31
61
  run_command(client, application)
32
- rescue Errno::ECONNRESET
33
- exit 1
34
- ensure
35
- server.close if @server
36
62
  end
37
63
 
38
64
  def boot_server
39
65
  env.socket_path.unlink if env.socket_path.exist?
40
66
 
41
- pid = fork {
42
- require "spring/server"
43
- Spring::Server.boot
44
- }
67
+ pid = Process.spawn(
68
+ "ruby",
69
+ "-r", "spring/server",
70
+ "-e", "Spring::Server.boot"
71
+ )
45
72
 
46
73
  until env.socket_path.exist?
47
74
  _, status = Process.waitpid2(pid, Process::WNOHANG)
@@ -50,6 +77,12 @@ module Spring
50
77
  end
51
78
  end
52
79
 
80
+ def stop_server
81
+ server.close
82
+ @server = nil
83
+ env.stop
84
+ end
85
+
53
86
  def verify_server_version
54
87
  server_version = server.gets.chomp
55
88
  if server_version != env.version
@@ -17,11 +17,11 @@ module Spring
17
17
  end
18
18
 
19
19
  def print_process(pid)
20
- puts `ps -p #{pid} -o pid= -o args=`
20
+ puts `ps -p #{pid} -o pid= -o command=`
21
21
  end
22
22
 
23
23
  def application_pids
24
- candidates = `ps -A -o ppid= -o pid=`.lines
24
+ candidates = `ps -ax -o ppid= -o pid=`.lines
25
25
  candidates.select { |l| l =~ /^(\s+)?#{env.pid} / }
26
26
  .map { |l| l.split(" ").last }
27
27
  end
@@ -3,35 +3,20 @@ require "spring/version"
3
3
  module Spring
4
4
  module Client
5
5
  class Stop < Command
6
- TIMEOUT = 2 # seconds
7
-
8
6
  def self.description
9
7
  "Stop all spring processes for this project."
10
8
  end
11
9
 
12
10
  def call
13
- if env.server_running?
14
- timeout = Time.now + TIMEOUT
15
- kill 'TERM'
16
- sleep 0.1 until !env.server_running? || Time.now >= timeout
17
-
18
- if env.server_running?
19
- $stderr.puts "Spring did not stop; killing forcibly."
20
- kill 'KILL'
21
- else
22
- puts "Spring stopped."
23
- end
24
- else
11
+ case env.stop
12
+ when :stopped
13
+ puts "Spring stopped."
14
+ when :killed
15
+ $stderr.puts "Spring did not stop; killing forcibly."
16
+ when :not_running
25
17
  puts "Spring is not running"
26
18
  end
27
19
  end
28
-
29
- def kill(sig)
30
- pid = env.pid
31
- Process.kill(sig, pid) if pid
32
- rescue Errno::ESRCH
33
- # already dead
34
- end
35
20
  end
36
21
  end
37
22
  end
@@ -41,10 +41,6 @@ module Spring
41
41
  end
42
42
  end
43
43
 
44
- def process_title
45
- [name, *ARGV].join(" ")
46
- end
47
-
48
44
  def gem_name
49
45
  if command.respond_to?(:gem_name)
50
46
  command.gem_name
@@ -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
@@ -32,8 +32,17 @@ module Spring
32
32
  # then we need to be under bundler.
33
33
  require "bundler/setup"
34
34
 
35
- Gem::Specification.map(&:name).grep(/^spring-commands-/).each do |command|
36
- require command
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
@@ -9,6 +9,7 @@ require "spring/configuration"
9
9
 
10
10
  module Spring
11
11
  IGNORE_SIGNALS = %w(INT QUIT)
12
+ STOP_TIMEOUT = 2 # seconds
12
13
 
13
14
  class Env
14
15
  attr_reader :log_file
@@ -32,13 +33,13 @@ module Spring
32
33
  end
33
34
 
34
35
  def tmp_path
35
- path = Pathname.new(Dir.tmpdir + "/spring")
36
+ path = Pathname.new(File.join(ENV['XDG_RUNTIME_DIR'] || Dir.tmpdir, "spring"))
36
37
  FileUtils.mkdir_p(path) unless path.exist?
37
38
  path
38
39
  end
39
40
 
40
41
  def application_id
41
- Digest::MD5.hexdigest(project_root.to_s)
42
+ Digest::MD5.hexdigest(RUBY_VERSION + project_root.to_s)
42
43
  end
43
44
 
44
45
  def socket_path
@@ -80,5 +81,29 @@ module Spring
80
81
  log_file.puts "[#{Time.now}] [#{Process.pid}] #{message}"
81
82
  log_file.flush
82
83
  end
84
+
85
+ def stop
86
+ if server_running?
87
+ timeout = Time.now + STOP_TIMEOUT
88
+ kill 'TERM'
89
+ sleep 0.1 until !server_running? || Time.now >= timeout
90
+
91
+ if server_running?
92
+ kill 'KILL'
93
+ :killed
94
+ else
95
+ :stopped
96
+ end
97
+ else
98
+ :not_running
99
+ end
100
+ end
101
+
102
+ def kill(sig)
103
+ pid = self.pid
104
+ Process.kill(sig, pid) if pid
105
+ rescue Errno::ESRCH
106
+ # already dead
107
+ end
83
108
  end
84
109
  end
data/lib/spring/sid.rb CHANGED
@@ -25,7 +25,7 @@ module Spring
25
25
  if Process.respond_to?(:getsid)
26
26
  # Ruby 2
27
27
  Process.getsid
28
- elsif defined?(Fiddle)
28
+ elsif defined?(Fiddle) and defined?(DL)
29
29
  # Ruby 1.9.3 compiled with libffi support
30
30
  fiddle_func.call(0)
31
31
  else