From 7102a3d7fc55067b6cda1a7eeb3b3452050d9b6b Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Fri, 4 Nov 2011 04:50:53 +0900 Subject: move Rails console top level methods to IRB context --- railties/lib/rails/console/app.rb | 48 +++++++++++++++++++---------------- railties/lib/rails/console/helpers.rb | 14 ++++++---- 2 files changed, 35 insertions(+), 27 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/console/app.rb b/railties/lib/rails/console/app.rb index 95c74baae2..cf081473a3 100644 --- a/railties/lib/rails/console/app.rb +++ b/railties/lib/rails/console/app.rb @@ -5,28 +5,32 @@ require 'action_controller' # work around the at_exit hook in test/unit, which kills IRB Test::Unit.run = true if Test::Unit.respond_to?(:run=) -# reference the global "app" instance, created on demand. To recreate the -# instance, pass a non-false value as the parameter. -def app(create=false) - @app_integration_instance = nil if create - @app_integration_instance ||= new_session do |sess| - sess.host! "www.example.com" - end -end +module IRB + module ExtendCommandBundle + # reference the global "app" instance, created on demand. To recreate the + # instance, pass a non-false value as the parameter. + def app(create=false) + @app_integration_instance = nil if create + @app_integration_instance ||= new_session do |sess| + sess.host! "www.example.com" + end + end -# create a new session. If a block is given, the new session will be yielded -# to the block before being returned. -def new_session - app = Rails.application - session = ActionDispatch::Integration::Session.new(app) - yield session if block_given? - session -end + # create a new session. If a block is given, the new session will be yielded + # to the block before being returned. + def new_session + app = Rails.application + session = ActionDispatch::Integration::Session.new(app) + yield session if block_given? + session + end -# reloads the environment -def reload!(print=true) - puts "Reloading..." if print - ActionDispatch::Reloader.cleanup! - ActionDispatch::Reloader.prepare! - true + # reloads the environment + def reload!(print=true) + puts "Reloading..." if print + ActionDispatch::Reloader.cleanup! + ActionDispatch::Reloader.prepare! + true + end + end end diff --git a/railties/lib/rails/console/helpers.rb b/railties/lib/rails/console/helpers.rb index 212fc6125a..070d3c2bbf 100644 --- a/railties/lib/rails/console/helpers.rb +++ b/railties/lib/rails/console/helpers.rb @@ -1,7 +1,11 @@ -def helper - @helper ||= ApplicationController.helpers -end +module IRB + module ExtendCommandBundle + def helper + @helper ||= ApplicationController.helpers + end -def controller - @controller ||= ApplicationController.new + def controller + @controller ||= ApplicationController.new + end + end end -- cgit v1.2.3 From 6d09f275c6e3224a8ea9a738512c90ee5334e20d Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 9 Nov 2011 15:42:19 +0900 Subject: Modulize Rails console methods so that other console libraries such as Pry can include these methods --- railties/lib/rails/application.rb | 2 ++ railties/lib/rails/console/app.rb | 4 ++-- railties/lib/rails/console/helpers.rb | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 82fffe86bb..e8b160448b 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -205,6 +205,8 @@ module Rails require "pp" require "rails/console/app" require "rails/console/helpers" + + IRB::ExtendCommandBundle.send :include, Rails::ConsoleMethods end end end diff --git a/railties/lib/rails/console/app.rb b/railties/lib/rails/console/app.rb index cf081473a3..23d57379ba 100644 --- a/railties/lib/rails/console/app.rb +++ b/railties/lib/rails/console/app.rb @@ -5,8 +5,8 @@ require 'action_controller' # work around the at_exit hook in test/unit, which kills IRB Test::Unit.run = true if Test::Unit.respond_to?(:run=) -module IRB - module ExtendCommandBundle +module Rails + module ConsoleMethods # reference the global "app" instance, created on demand. To recreate the # instance, pass a non-false value as the parameter. def app(create=false) diff --git a/railties/lib/rails/console/helpers.rb b/railties/lib/rails/console/helpers.rb index 070d3c2bbf..230d3d9d04 100644 --- a/railties/lib/rails/console/helpers.rb +++ b/railties/lib/rails/console/helpers.rb @@ -1,5 +1,5 @@ -module IRB - module ExtendCommandBundle +module Rails + module ConsoleMethods def helper @helper ||= ApplicationController.helpers end -- cgit v1.2.3