From 1348bebaa74c689c3582916d9bc14724d17d257a Mon Sep 17 00:00:00 2001 From: Ryan Fitzgerald Date: Wed, 8 Feb 2012 12:59:15 -0800 Subject: [PATCH] Rearrange the load process (fix #13) * Only override IRB, load console helpers, etc., when we're running in the context of "rails console". * Require pry at the top so that binding.pry will still work in other contexts. --- lib/pry-rails.rb | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/pry-rails.rb b/lib/pry-rails.rb index 42d729c..3458327 100644 --- a/lib/pry-rails.rb +++ b/lib/pry-rails.rb @@ -1,23 +1,26 @@ require "pry-rails/version" module PryRails - if(defined?(::Rails) and ::Rails::VERSION::MAJOR >= 3) - class Railtie < ::Rails::Railtie - silence_warnings do - begin - require 'pry' - Rails::Console::IRB = Pry + begin + require 'pry' + + if (defined?(::Rails::Console) and ::Rails::VERSION::MAJOR >= 3) + class Railtie < ::Rails::Railtie + silence_warnings do + ::Rails::Console::IRB = Pry + unless defined?(Pry::ExtendCommandBundle) Pry::ExtendCommandBundle = Module.new end + if ::Rails::VERSION::MINOR >= 2 require "rails/console/app" require "rails/console/helpers" - TOPLEVEL_BINDING.eval('self').extend Rails::ConsoleMethods + TOPLEVEL_BINDING.eval('self').extend ::Rails::ConsoleMethods end - rescue LoadError end end end + rescue LoadError end end