提交 9cda6a32 编写于 作者: N Nikita Afanasenko

Use `tag!` instead of `method_missing` in `to_xml` conversions.

Since version `3.0.x` `Builder` caches method passed to `method_missing` each time. This commit replaces `method_missing` call with `tag!` call to prevent method redefinition on each `to_xml` call with the same builder.
上级 c449462f
## Rails 4.0.0 (unreleased) ##
* `to_xml` conversions now use builder's `tag!` method instead of explicit invocation of `method_missing`.
*Nikita Afanasenko*
* Fixed timezone mapping of the Solomon Islands. *Steve Klabnik*
* Make callstack attribute optional in
......
......@@ -194,7 +194,7 @@ def to_xml(options = {})
options = options.dup
options[:indent] ||= 2
options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
options[:builder] ||= Builder::XmlMarkup.new(indent: options[:indent])
options[:root] ||= \
if first.class != Hash && all? { |e| e.is_a?(first.class) }
underscored = ActiveSupport::Inflector.underscore(first.class.name)
......@@ -208,12 +208,12 @@ def to_xml(options = {})
root = ActiveSupport::XmlMini.rename_key(options[:root].to_s, options)
children = options.delete(:children) || root.singularize
attributes = options[:skip_types] ? {} : {:type => 'array'}
attributes = options[:skip_types] ? {} : { type: 'array' }
if empty?
builder.tag!(root, attributes)
else
builder.__send__(:method_missing, root, attributes) do
builder.tag!(root, attributes) do
each { |value| ActiveSupport::XmlMini.to_tag(children, value, options) }
yield builder if block_given?
end
......
......@@ -74,14 +74,14 @@ def to_xml(options = {})
options = options.dup
options[:indent] ||= 2
options[:root] ||= 'hash'
options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
options[:builder] ||= Builder::XmlMarkup.new(indent: options[:indent])
builder = options[:builder]
builder.instruct! unless options.delete(:skip_instruct)
root = ActiveSupport::XmlMini.rename_key(options[:root].to_s, options)
builder.__send__(:method_missing, root) do
builder.tag!(root) do
each { |key, value| ActiveSupport::XmlMini.to_tag(key, value, options) }
yield builder if block_given?
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册