From 559c4292bcd132e87b50aa8f0807f2684cf234b8 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 22 Nov 2010 14:07:28 -0200 Subject: [PATCH] Remove unneeded metaprogramming and method generation in favor of direct definition --- .../lib/action_controller/metal/renderers.rb | 34 ++++++------------- 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/actionpack/lib/action_controller/metal/renderers.rb b/actionpack/lib/action_controller/metal/renderers.rb index f9b226b7c9..41bcae75c9 100644 --- a/actionpack/lib/action_controller/metal/renderers.rb +++ b/actionpack/lib/action_controller/metal/renderers.rb @@ -15,30 +15,12 @@ module ActionController end module ClassMethods - def _write_render_options - renderers = _renderers.map do |name, value| - <<-RUBY_EVAL - if options.key?(:#{name}) - _process_options(options) - return _render_option_#{name}(options.delete(:#{name}), options) - end - RUBY_EVAL - end - - class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1 - def _handle_render_options(options) - #{renderers.join} - end - RUBY_EVAL - end - def use_renderers(*args) new = _renderers.dup args.each do |key| new[key] = RENDERERS[key] end self._renderers = new.freeze - _write_render_options end alias use_renderer use_renderers end @@ -47,11 +29,20 @@ module ActionController _handle_render_options(options) || super end + def _handle_render_options(options) + _renderers.each do |name, value| + if options.key?(name.to_sym) + _process_options(options) + return send("_render_option_#{name}", options.delete(name.to_sym), options) + end + end + nil + end + RENDERERS = {} def self.add(key, &block) define_method("_render_option_#{key}", &block) RENDERERS[key] = block - All._write_render_options end module All @@ -61,13 +52,8 @@ module ActionController INCLUDED = [] included do self._renderers = RENDERERS - _write_render_options INCLUDED << self end - - def self._write_render_options - INCLUDED.each(&:_write_render_options) - end end add :json do |json, options|