module Spring

### WHY SPRING VENDORS A JSON LIBRARY ###

Spring is designed to be able to run outside of bundler. Ruby has a built-in “json” library, which we could use. However if we require that, and somebody has a different (perhaps newer) version of the json gem in their Gemfile, it will never get used since we already required the older version of the json library from the stdlib. Therefore, we are vendoring a json library for our own use in order to not interfere.

Some parts adapted from golang.org/src/pkg/json/decode.go and golang.org/src/pkg/utf8/utf8.go

Constants

IGNORE_SIGNALS
ORIGINAL_ENV
STOP_TIMEOUT
VERSION

Attributes

application_root[RW]
commands[R]
quiet[RW]
watch_interval[RW]
watch_method[R]
watcher[W]

Public Class Methods

after_fork(&block) click to toggle source
# File lib/spring/configuration.rb, line 15
def after_fork(&block)
  after_fork_callbacks << block
end
after_fork_callbacks() click to toggle source
# File lib/spring/configuration.rb, line 11
def after_fork_callbacks
  @after_fork_callbacks ||= []
end
application_root_path() click to toggle source
# File lib/spring/configuration.rb, line 23
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
command(name) click to toggle source
# File lib/spring/commands.rb, line 19
def self.command(name)
  commands.fetch name
end
command?(name) click to toggle source
# File lib/spring/commands.rb, line 15
def self.command?(name)
  commands.include? name
end
failsafe_thread() { || ... } click to toggle source
# File lib/spring/failsafe_thread.rb, line 5
def failsafe_thread
  Thread.new {
    begin
      yield
    rescue
    end
  }
end
gemfile() click to toggle source
# File lib/spring/configuration.rb, line 7
def gemfile
  ENV['BUNDLE_GEMFILE'] || "Gemfile"
end
project_root_path() click to toggle source
# File lib/spring/configuration.rb, line 36
def project_root_path
  @project_root_path ||= find_project_root(Pathname.new(File.expand_path(Dir.pwd)))
end
register_command(name, command = nil) click to toggle source
# File lib/spring/commands.rb, line 11
def self.register_command(name, command = nil)
  commands[name] = CommandWrapper.new(name, command)
end
verify_environment() click to toggle source
# File lib/spring/configuration.rb, line 19
def verify_environment
  application_root_path
end
watch(*items) click to toggle source
# File lib/spring/watcher.rb, line 27
def self.watch(*items)
  watcher.add(*items)
end
watch_method=(method) click to toggle source
# File lib/spring/watcher.rb, line 11
def self.watch_method=(method)
  if method.is_a?(Class)
    @watch_method = method
  else
    require "spring/watcher/#{method}"
    @watch_method = Watcher.const_get(method.to_s.gsub(/(^.|_.)/) { $1[-1].upcase })
  end
end
watcher() click to toggle source
# File lib/spring/watcher.rb, line 23
def self.watcher
  @watcher ||= watch_method.new(Spring.application_root_path, watch_interval)
end

Private Class Methods

find_project_root(current_dir) click to toggle source
# File lib/spring/configuration.rb, line 42
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