1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Refactor to make renderers a Set

This commit is contained in:
Jose and Yehuda 2011-09-26 18:57:49 -04:00
parent 8ff7693a8d
commit a4c04a43cc

View file

@ -1,5 +1,6 @@
require 'active_support/core_ext/class/attribute' require 'active_support/core_ext/class/attribute'
require 'active_support/core_ext/object/blank' require 'active_support/core_ext/object/blank'
require 'set'
module ActionController module ActionController
# See <tt>Renderers.add</tt> # See <tt>Renderers.add</tt>
@ -12,16 +13,13 @@ module ActionController
included do included do
class_attribute :_renderers class_attribute :_renderers
self._renderers = {}.freeze self._renderers = Set.new.freeze
end end
module ClassMethods module ClassMethods
def use_renderers(*args) def use_renderers(*args)
new = _renderers.dup renderers = _renderers + args
args.each do |key| self._renderers = renderers.freeze
new[key] = RENDERERS[key]
end
self._renderers = new.freeze
end end
alias use_renderer use_renderers alias use_renderer use_renderers
end end
@ -31,10 +29,10 @@ module ActionController
end end
def _handle_render_options(options) def _handle_render_options(options)
_renderers.each do |name, value| _renderers.each do |name|
if options.key?(name.to_sym) if options.key?(name)
_process_options(options) _process_options(options)
return send("_render_option_#{name}", options.delete(name.to_sym), options) return send("_render_option_#{name}", options.delete(name), options)
end end
end end
nil nil
@ -42,7 +40,7 @@ module ActionController
# Hash of available renderers, mapping a renderer name to its proc. # Hash of available renderers, mapping a renderer name to its proc.
# Default keys are :json, :js, :xml. # Default keys are :json, :js, :xml.
RENDERERS = {} RENDERERS = Set.new
# Adds a new renderer to call within controller actions. # Adds a new renderer to call within controller actions.
# A renderer is invoked by passing its name as an option to # A renderer is invoked by passing its name as an option to
@ -79,7 +77,7 @@ module ActionController
# <tt>ActionController::MimeResponds#respond_with</tt> # <tt>ActionController::MimeResponds#respond_with</tt>
def self.add(key, &block) def self.add(key, &block)
define_method("_render_option_#{key}", &block) define_method("_render_option_#{key}", &block)
RENDERERS[key] = block RENDERERS << key.to_sym
end end
module All module All