From 1a81a1b38278c04aca1f710b739a7d30a03bbd56 Mon Sep 17 00:00:00 2001 From: Eric Lindvall Date: Tue, 1 May 2012 23:32:43 -0700 Subject: [PATCH 1/2] Provide a simple way to prevent bundler auto-loading Most cases of problems we see with conflicts with sugar.rb are due to bundler autoloading god into Rails processes when it really doesn't need to be. --- bin/god | 4 +++- lib/god.rb | 10 ++++++++-- test/helper.rb | 6 +++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/bin/god b/bin/god index f7362388..9219065a 100755 --- a/bin/god +++ b/bin/god @@ -4,7 +4,6 @@ STDOUT.sync = true $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib]) -require 'rubygems' require 'optparse' require 'drb' require 'yaml' @@ -105,6 +104,9 @@ begin abort("Invalid log level '#{options[:log_level]}'") end + # Use this flag to actually load all of the god infrastructure + $should_really_load_god = true + # dispatch if !options[:config] && options[:version] require 'god' diff --git a/lib/god.rb b/lib/god.rb index eb8318f4..2f76e42b 100644 --- a/lib/god.rb +++ b/lib/god.rb @@ -1,4 +1,8 @@ -$:.unshift File.dirname(__FILE__) # For use/testing when no gem is installed +# Bail out before loading anything unless this flag is set. +# +# We are doing this to guard against bundler autoloading because there is +# no value in loading god in most processes. +if $should_really_load_god # core require 'stringio' @@ -726,7 +730,7 @@ def self.at_exit # private # Match a shortened pattern against a list of String candidates. - # The pattern is expanded into a regular expression by + # The pattern is expanded into a regular expression by # inserting .* between each character. # # pattern - The String containing the abbreviation. @@ -756,3 +760,5 @@ def self.pattern_match(pattern, list) at_exit do God.at_exit if $run end + +end \ No newline at end of file diff --git a/test/helper.rb b/test/helper.rb index 063924bb..4d201100 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -1,4 +1,8 @@ -require 'rubygems' +$:.unshift File.expand_path('../../lib', __FILE__) # For use/testing when no gem is installed + +# Use this flag to actually load all of the god infrastructure +$should_really_load_god = true + require File.join(File.dirname(__FILE__), *%w[.. lib god sys_logger]) require File.join(File.dirname(__FILE__), *%w[.. lib god]) God::EventHandler.load From 64a0ec2b1a4e3c3be5405fd66d4a0d167d119148 Mon Sep 17 00:00:00 2001 From: Eric Lindvall Date: Wed, 9 May 2012 14:39:03 -0700 Subject: [PATCH 2/2] Shorten the name of the global to $load_god --- bin/god | 2 +- lib/god.rb | 2 +- test/helper.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/god b/bin/god index 9219065a..149df077 100755 --- a/bin/god +++ b/bin/god @@ -105,7 +105,7 @@ begin end # Use this flag to actually load all of the god infrastructure - $should_really_load_god = true + $load_god = true # dispatch if !options[:config] && options[:version] diff --git a/lib/god.rb b/lib/god.rb index 2f76e42b..931fd151 100644 --- a/lib/god.rb +++ b/lib/god.rb @@ -2,7 +2,7 @@ # # We are doing this to guard against bundler autoloading because there is # no value in loading god in most processes. -if $should_really_load_god +if $load_god # core require 'stringio' diff --git a/test/helper.rb b/test/helper.rb index 4d201100..09438ddb 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -1,7 +1,7 @@ $:.unshift File.expand_path('../../lib', __FILE__) # For use/testing when no gem is installed # Use this flag to actually load all of the god infrastructure -$should_really_load_god = true +$load_god = true require File.join(File.dirname(__FILE__), *%w[.. lib god sys_logger]) require File.join(File.dirname(__FILE__), *%w[.. lib god])