From 763277d35ada88af31b000a5b925cc40471ca91a Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Tue, 18 Sep 2018 12:09:14 +0200 Subject: [PATCH] Enable Spring and bootsnap for faster app load and respone times Signed-off-by: Sebastian Serth --- bin/rails | 5 +++++ bin/rake | 5 +++++ bin/spring | 21 ++++++++++----------- config/boot.rb | 2 +- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/bin/rails b/bin/rails index 07396602..5badb2fd 100755 --- a/bin/rails +++ b/bin/rails @@ -1,4 +1,9 @@ #!/usr/bin/env ruby +begin + load File.expand_path('../spring', __FILE__) +rescue LoadError => e + raise unless e.message.include?('spring') +end APP_PATH = File.expand_path('../config/application', __dir__) require_relative '../config/boot' require 'rails/commands' diff --git a/bin/rake b/bin/rake index 17240489..d87d5f57 100755 --- a/bin/rake +++ b/bin/rake @@ -1,4 +1,9 @@ #!/usr/bin/env ruby +begin + load File.expand_path('../spring', __FILE__) +rescue LoadError => e + raise unless e.message.include?('spring') +end require_relative '../config/boot' require 'rake' Rake.application.run diff --git a/bin/spring b/bin/spring index 253ec37c..fb2ec2eb 100755 --- a/bin/spring +++ b/bin/spring @@ -1,18 +1,17 @@ #!/usr/bin/env ruby -# This file loads spring without using Bundler, in order to be fast -# It gets overwritten when you run the `spring binstub` command +# This file loads spring without using Bundler, in order to be fast. +# It gets overwritten when you run the `spring binstub` command. unless defined?(Spring) - require "rubygems" - require "bundler" + require 'rubygems' + require 'bundler' - if match = Bundler.default_lockfile.read.match(/^GEM$.*?^ spring \((.*?)\)$.*?^$/m) - ENV["GEM_PATH"] = ([Bundler.bundle_path.to_s] + Gem.path).join(File::PATH_SEPARATOR) - ENV["GEM_HOME"] = "" - Gem.paths = ENV - - gem "spring", match[1] - require "spring/binstub" + lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read) + spring = lockfile.specs.detect { |spec| spec.name == "spring" } + if spring + Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path + gem 'spring', spring.version + require 'spring/binstub' end end diff --git a/config/boot.rb b/config/boot.rb index 4423c97f..b9e460ce 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,4 +1,4 @@ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) require 'bundler/setup' # Set up gems listed in the Gemfile. -# require 'bootsnap/setup' # Speed up boot time by caching expensive operations. +require 'bootsnap/setup' # Speed up boot time by caching expensive operations.