module ActiveSupport::XmlMini

XmlMini

To use the much faster libxml parser:

gem 'libxml-ruby'
XmlMini.backend = 'LibXML'

Constants

DEFAULT_ENCODINGS
FORMATTING
PARSING
TYPE_NAMES

Attributes

Public Instance Methods

# File activesupport/lib/active_support/xml_mini.rb, line 97
def backend
  current_thread_backend || @backend
end
# File activesupport/lib/active_support/xml_mini.rb, line 101
def backend=(name)
  backend = name && cast_backend_name_to_module(name)
  self.current_thread_backend = backend if current_thread_backend
  @backend = backend
end
# File activesupport/lib/active_support/xml_mini.rb, line 148
def rename_key(key, options = {})
  camelize  = options[:camelize]
  dasherize = !options.has_key?(:dasherize) || options[:dasherize]
  if camelize
    key = true == camelize ? key.camelize : key.camelize(camelize)
  end
  key = _dasherize(key) if dasherize
  key
end
# File activesupport/lib/active_support/xml_mini.rb, line 115
def to_tag(key, value, options)
  type_name = options.delete(:type)
  merged_options = options.merge(root: key, skip_instruct: true)

  if value.is_a?(::Method) || value.is_a?(::Proc)
    if value.arity == 1
      value.call(merged_options)
    else
      value.call(merged_options, key.to_s.singularize)
    end
  elsif value.respond_to?(:to_xml)
    value.to_xml(merged_options)
  else
    type_name ||= TYPE_NAMES[value.class.name]
    type_name ||= value.class.name if value && !value.respond_to?(:to_str)
    type_name   = type_name.to_s   if type_name
    type_name   = "dateTime" if type_name == "datetime"

    key = rename_key(key.to_s, options)

    attributes = options[:skip_types] || type_name.nil? ? {} : { type: type_name }
    attributes[:nil] = true if value.nil?

    encoding = options[:encoding] || DEFAULT_ENCODINGS[type_name]
    attributes[:encoding] = encoding if encoding

    formatted_value = FORMATTING[type_name] && !value.nil? ?
      FORMATTING[type_name].call(value) : value

    options[:builder].tag!(key, formatted_value, attributes)
  end
end
# File activesupport/lib/active_support/xml_mini.rb, line 107
def with_backend(name)
  old_backend = current_thread_backend
  self.current_thread_backend = name && cast_backend_name_to_module(name)
  yield
ensure
  self.current_thread_backend = old_backend
end