Skip to content

Instantly share code, notes, and snippets.

@lloeki
Created July 9, 2012 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lloeki/3076389 to your computer and use it in GitHub Desktop.
Save lloeki/3076389 to your computer and use it in GitHub Desktop.
Monkeypatching rails 2.x to load Mongrel with bundler
# ...8<...
Rails.boot!
# see http://gembundler.com/rails23.html to make Bundler work with Rails 2.x (tested with 2.1, 2.2 and 2.3)
# bundler with rails 2.x prevents finding mongrel_rails in PATH
if $0 == "script/server"
# ensure active_support is loaded
require 'active_support'
module MongrelFix
puts "Patching load() for mongrel_rails"
# Patching load from active_support (watching out for recursion)
def self.included(base)
base.class_eval do
unless defined? load_without_mongrel_fixed
alias_method :load_without_mongrel_fixed, :load_without_new_constant_marking
define_method :load_with_mongrel_fixed do |file, *extras|
if file == 'mongrel_rails'
puts "Fixing mongrel_rails filename path"
# Using bundled mongrel_rails
file = %x[bundle show mongrel].strip() + '/bin/mongrel_rails'
end
load_without_mongrel_fixed(file, *extras)
end
alias_method :load_without_new_constant_marking, :load_with_mongrel_fixed
end
end
end
end unless defined? load_with_mongrel_fixed
Object.instance_eval { include MongrelFix }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment