Skip to content
This repository
Browse code

Merge pull request #8111 from nikitug/use_tag_instead_of_method_missi…

…ng_in_xml_builder

Use `tag!` instead of `method_missing` in `to_xml` conversions.
  • Loading branch information...
commit f786469f54332458ed60a1bbefec3125afe5f64b 2 parents 7c3bc58 + 9cda6a3
Carlos Antonio da Silva authored
4  activesupport/CHANGELOG.md
Source Rendered
... ...
@@ -1,5 +1,9 @@
1 1
 ## Rails 4.0.0 (unreleased) ##
2 2
 
  3
+*   `to_xml` conversions now use builder's `tag!` method instead of explicit invocation of `method_missing`.
  4
+
  5
+    *Nikita Afanasenko*
  6
+
3 7
 *   Fixed timezone mapping of the Solomon Islands. *Steve Klabnik*
4 8
 
5 9
 *   Make callstack attribute optional in
6  activesupport/lib/active_support/core_ext/array/conversions.rb
@@ -194,7 +194,7 @@ def to_xml(options = {})
194 194
 
195 195
     options = options.dup
196 196
     options[:indent]  ||= 2
197  
-    options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
  197
+    options[:builder] ||= Builder::XmlMarkup.new(indent: options[:indent])
198 198
     options[:root]    ||= \
199 199
       if first.class != Hash && all? { |e| e.is_a?(first.class) }
200 200
         underscored = ActiveSupport::Inflector.underscore(first.class.name)
@@ -208,12 +208,12 @@ def to_xml(options = {})
208 208
 
209 209
     root = ActiveSupport::XmlMini.rename_key(options[:root].to_s, options)
210 210
     children = options.delete(:children) || root.singularize
211  
-    attributes = options[:skip_types] ? {} : {:type => 'array'}
  211
+    attributes = options[:skip_types] ? {} : { type: 'array' }
212 212
 
213 213
     if empty?
214 214
       builder.tag!(root, attributes)
215 215
     else
216  
-      builder.__send__(:method_missing, root, attributes) do
  216
+      builder.tag!(root, attributes) do
217 217
         each { |value| ActiveSupport::XmlMini.to_tag(children, value, options) }
218 218
         yield builder if block_given?
219 219
       end
4  activesupport/lib/active_support/core_ext/hash/conversions.rb
@@ -74,14 +74,14 @@ def to_xml(options = {})
74 74
     options = options.dup
75 75
     options[:indent]  ||= 2
76 76
     options[:root]    ||= 'hash'
77  
-    options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
  77
+    options[:builder] ||= Builder::XmlMarkup.new(indent: options[:indent])
78 78
 
79 79
     builder = options[:builder]
80 80
     builder.instruct! unless options.delete(:skip_instruct)
81 81
 
82 82
     root = ActiveSupport::XmlMini.rename_key(options[:root].to_s, options)
83 83
 
84  
-    builder.__send__(:method_missing, root) do
  84
+    builder.tag!(root) do
85 85
       each { |key, value| ActiveSupport::XmlMini.to_tag(key, value, options) }
86 86
       yield builder if block_given?
87 87
     end

0 notes on commit f786469

Please sign in to comment.
Something went wrong with that request. Please try again.