Class/Module Index [+]

Quicksearch

ActiveSupport::XmlMini

XmlMini

To use the much faster libxml parser:

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

Attributes

backend[R]

Public Instance Methods

backend=(name) click to toggle source
# File lib/active_support/xml_mini.rb, line 80
def backend=(name)
  if name.is_a?(Module)
    @backend = name
  else
    require "active_support/xml_mini/#{name.to_s.downcase}"
    @backend = ActiveSupport.const_get("XmlMini_#{name}")
  end
end
rename_key(key, options = {}) click to toggle source
# File lib/active_support/xml_mini.rb, line 128
def rename_key(key, options = {})
  camelize  = options.has_key?(:camelize) && options[:camelize]
  dasherize = !options.has_key?(:dasherize) || options[:dasherize]
  key = key.camelize  if camelize
  key = _dasherize(key) if dasherize
  key
end
to_tag(key, value, options) click to toggle source
# File lib/active_support/xml_mini.rb, line 96
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

    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
with_backend(name) click to toggle source
# File lib/active_support/xml_mini.rb, line 89
def with_backend(name)
  old_backend, self.backend = backend, name
  yield
ensure
  self.backend = old_backend
end

Protected Instance Methods

_dasherize(key) click to toggle source
# File lib/active_support/xml_mini.rb, line 138
def _dasherize(key)
  key.gsub(/(?!^[_]*)_(?![_]*$)/, '-')
end
_parse_file(file, entity) click to toggle source
# File lib/active_support/xml_mini.rb, line 152
def _parse_file(file, entity)
  f = StringIO.new(ActiveSupport::Base64.decode64(file))
  f.extend(FileLike)
  f.original_filename = entity['name']
  f.content_type = entity['content_type']
  f
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.