Created
July 9, 2012 12:57
-
-
Save lloeki/3076389 to your computer and use it in GitHub Desktop.
Monkeypatching rails 2.x to load Mongrel with bundler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ...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