Sha256: ad16cb855635ab94cab2cbe6fca68d108dd4d3711fc6a033f99cb19227cbece5

Contents?: true

Size: 1.23 KB

Versions: 5

Compression:

Stored size: 1.23 KB

Contents

require "spring/errors"

module Spring
  class << self
    attr_accessor :application_root, :quiet

    def gemfile
      if /\s1.9.[0-9]/ ===  Bundler.ruby_scope.gsub(/[\/\s]+/,'')
        ENV["BUNDLE_GEMFILE"] || "Gemfile"
      else
        Bundler.default_gemfile
      end
    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

  self.quiet = false
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
spring-3.0.0 lib/spring/configuration.rb
nrispring-2.1.3 lib/spring/configuration.rb
nrispring-2.1.2 lib/spring/configuration.rb
nrispring-2.1.1 lib/spring/configuration.rb
spring-2.1.1 lib/spring/configuration.rb