Skip to content

Instantly share code, notes, and snippets.

@atmos
Created October 12, 2010 00:56
Show Gist options
  • Select an option

  • Save atmos/621485 to your computer and use it in GitHub Desktop.

Select an option

Save atmos/621485 to your computer and use it in GitHub Desktop.
# Lightweight environment configuration.
#
# This file is useful when you want to load a small portion of the whole
# github environment for daemons that want to keep their resident memory
# usage low or commands that need to boot fast.
#
# Determine RAILS_ROOT from this file's location
if !defined?(RAILS_ROOT)
ENV['RAILS_ROOT'] ||= File.expand_path('../..', __FILE__)
RAILS_ROOT = ENV['RAILS_ROOT'].dup
end
# Determine RAILS_ENV from the environment or current hostname
if !defined?(RAILS_ENV)
ENV['RAILS_ENV'] ||=
if RAILS_ROOT == '/data/github/current'
if `hostname`.include?('stg.github.com')
'staging'
else
'production'
end
else
'development'
end
RAILS_ENV = ENV['RAILS_ENV'].dup
end
# Disallow use of system gems by default in staging and production environments
# or when the GEM_STRICT environment variable is set. This ensures the gem
# environment is totally isolated to only stuff specified in the Gemfile.
if %w(staging production).include?(RAILS_ENV) || ENV['GEM_STRICT']
ENV['GEM_PATH'] = "#{RAILS_ROOT}/vendor/gems"
ENV['GEM_HOME'] = "#{RAILS_ROOT}/vendor/gems"
elsif !ENV['GEM_PATH'].to_s.include?("#{RAILS_ROOT}/vendor/gems")
ENV['GEM_PATH'] =
["#{RAILS_ROOT}/vendor/gems", ENV['GEM_PATH']].compact.join(':')
end
# put RAILS_ROOT/bin on PATH
binpath = "#{RAILS_ROOT}/bin"
ENV['PATH'] = "#{binpath}:#{ENV['PATH']}" if !ENV['PATH'].include?(binpath)
# Setup bundled gem load path.
paths = File.read("#{RAILS_ROOT}/.bundle/loadpath").split("\n")
paths.each do |path|
next if path =~ /^[ \t]*(?:#|$)/
path = File.join(RAILS_ROOT, path)
next if !File.directory?(path) || $:.include?(path)
$:.unshift path
end
# Add RAILS_ROOT to load path so you can require config/initializers/file
# and stuff like that.
$:.unshift RAILS_ROOT
# Add RAILS_ROOT/lib to load path if it isn't already there
$:.unshift "#{RAILS_ROOT}/lib" if !$:.include?("#{RAILS_ROOT}/lib")
github git:(master) irb
>> require "bundler"
=> true
>> require "bundler/setup"
=> true
>> File.open(".bundle/loadpath", "w") { |fp| $:.each { |path| fp.puts(path) } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment