1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
require "spring/errors"
module Spring
class << self
attr_accessor :application_root
def gemfile
ENV['BUNDLE_GEMFILE'] || "Gemfile"
end
def after_fork_callbacks
@after_fork_callbacks ||= []
end
def after_fork(&block)
after_fork_callbacks << block
end
def verify_environment
application_root_path
end
def application_root_path
@application_root_path ||= begin
if application_root
path = Pathname.new(File.expand_path(application_root))
else
path = project_root_path
end
raise MissingApplication.new(path) unless path.join("config/application.rb").exist?
path
end
end
def project_root_path
@project_root_path ||= find_project_root(Pathname.new(File.expand_path(Dir.pwd)))
end
private
def find_project_root(current_dir)
if current_dir.join(gemfile).exist?
current_dir
elsif current_dir.root?
raise UnknownProject.new(Dir.pwd)
else
find_project_root(current_dir.parent)
end
end
end
end
|