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]
watch_interval[RW]
watch_method[R]
watcher[W]

Public Class Methods

after_fork(&block) click to toggle source
# File lib/spring-jruby/configuration.rb, line 15
def after_fork(&block)
  after_fork_callbacks << block
end
after_fork_callbacks() click to toggle source
# File lib/spring-jruby/configuration.rb, line 11
def after_fork_callbacks
  @after_fork_callbacks ||= []
end
application_root_path() click to toggle source
# File lib/spring-jruby/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-jruby/commands.rb, line 19
def self.command(name)
  commands.fetch name
end
command?(name) click to toggle source
# File lib/spring-jruby/commands.rb, line 15
def self.command?(name)
  commands.include? name
end
fork?() click to toggle source
# File lib/spring-jruby/platform.rb, line 2
def self.fork?
  Process.respond_to?(:fork)
end
gemfile() click to toggle source
# File lib/spring-jruby/configuration.rb, line 7
def gemfile
  ENV['BUNDLE_GEMFILE'] || "Gemfile"
end
jruby?() click to toggle source
# File lib/spring-jruby/platform.rb, line 6
def self.jruby?
  RUBY_PLATFORM == "java"
end
pool_min_free_workers() click to toggle source
# File lib/spring-jruby/configuration.rb, line 40
def pool_min_free_workers
  2
end
pool_spawn_parallel() click to toggle source
# File lib/spring-jruby/configuration.rb, line 44
def pool_spawn_parallel
  true
end
project_root_path() click to toggle source
# File lib/spring-jruby/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-jruby/commands.rb, line 11
def self.register_command(name, command = nil)
  commands[name] = CommandWrapper.new(name, command)
end
ruby_bin() click to toggle source
# File lib/spring-jruby/platform.rb, line 10
def self.ruby_bin
  if RUBY_PLATFORM == "java"
    "jruby"
  else
    "ruby"
  end
end
verify_environment() click to toggle source
# File lib/spring-jruby/configuration.rb, line 19
def verify_environment
  application_root_path
end
watch(*items) click to toggle source
# File lib/spring-jruby/watcher.rb, line 27
def self.watch(*items)
  watcher.add(*items)
end
watch_method=(method) click to toggle source
# File lib/spring-jruby/watcher.rb, line 11
def self.watch_method=(method)
  if method.is_a?(Class)
    @watch_method = method
  else
    require "spring-jruby/watcher/#{method}"
    @watch_method = Watcher.const_get(method.to_s.gsub(/(^.|_.)/) { $1[-1].upcase })
  end
end
watcher() click to toggle source
# File lib/spring-jruby/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-jruby/configuration.rb, line 50
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