Permalink
Browse files

Merge pull request #14597 from matthewd/kernel_y_for_1_9_option_1

Ensure we supply Kernel#y for 1.9 too
  • Loading branch information...
1 parent 1778b07 commit 2fb13658b05fb416c45423ffddcd99734c025ac6 @rafaelfranca rafaelfranca committed Apr 4, 2014
Showing with 29 additions and 10 deletions.
  1. +19 −0 railties/lib/rails/application.rb
  2. +0 −2 railties/lib/rails/engine.rb
  3. +10 −8 railties/lib/rails/railtie.rb
@@ -332,6 +332,25 @@ def helpers_paths #:nodoc:
config.helpers_paths
end
+ console do
+ require "pp"
+ end
+
+ console do
+ unless ::Kernel.private_method_defined?(:y)
+ if RUBY_VERSION >= '2.0'
+ require "psych/y"
+ else
+ module ::Kernel
+ def y(*objects)
+ puts ::Psych.dump_stream(*objects)
+ end
+ private :y
+ end
+ end
+ end
+ end
+
protected
alias :build_middleware_stack :app
@@ -429,8 +429,6 @@ def initialize
# Load console and invoke the registered hooks.
# Check <tt>Rails::Railtie.console</tt> for more info.
def load_console(app=self)
- require "pp"
- require "psych/y"
require "rails/console/app"
require "rails/console/helpers"
run_console_blocks(app)
@@ -221,26 +221,28 @@ def railtie_namespace
protected
def run_console_blocks(app) #:nodoc:
- self.class.console.each { |block| block.call(app) }
+ each_registered_block(:console) { |block| block.call(app) }
end
def run_generators_blocks(app) #:nodoc:
- self.class.generators.each { |block| block.call(app) }
+ each_registered_block(:generators) { |block| block.call(app) }
end
def run_runner_blocks(app) #:nodoc:
- self.class.runner.each { |block| block.call(app) }
+ each_registered_block(:runner) { |block| block.call(app) }
end
def run_tasks_blocks(app) #:nodoc:
extend Rake::DSL
- self.class.rake_tasks.each { |block| instance_exec(app, &block) }
+ each_registered_block(:rake_tasks) { |block| instance_exec(app, &block) }
+ end
- # Load also tasks from all superclasses
- klass = self.class.superclass
+ private
- while klass.respond_to?(:rake_tasks)
- klass.rake_tasks.each { |t| instance_exec(app, &t) }
+ def each_registered_block(type, &block)
+ klass = self.class
+ while klass.respond_to?(type)
+ klass.public_send(type).each(&block)
klass = klass.superclass
end
end

0 comments on commit 2fb1365

Please sign in to comment.