mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Remove unneeded metaprogramming and method generation in favor of direct definition
This commit is contained in:
parent
115abd52b6
commit
559c4292bc
1 changed files with 10 additions and 24 deletions
|
@ -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|
|
||||
|
|
Loading…
Reference in a new issue