Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/ad_gear/core_ext.rb
Overview
ActiveSupport’s Array#to_xml will build an XML with root set to the full class name including module(s) it may be nested in - we don’t want that, we want it to be just the class name, make it so with this monkey patch…
Note this is loaded last from AdGear.config= after ActiveSupport has already been loaded. We cannot simply override because ActiveSupport does lazy loading.
Instance Method Summary collapse
Instance Method Details
#to_xml_with_module_prefixing(options = {}) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/ad_gear/core_ext.rb', line 10 def to_xml_with_module_prefixing( = {}) raise "Not all elements respond to to_xml in #{self.inspect}" unless all? { |e| e.respond_to? :to_xml } root = all? { |e| e.is_a?(first.class) && first.class.to_s != "Hash" } ? ActiveSupport::Inflector.pluralize(ActiveSupport::Inflector.underscore(first.class.to_s.split("::").last)) : "records" to_xml_without_module_prefixing({ :root => root }.merge()) end |