XmlMini

To use the much faster libxml parser:

  gem 'libxml-ruby', '=0.9.7'
  XmlMini.backend = 'LibXML'
Methods
#
B
R
T
W
Classes and Modules
Constants
DEFAULT_ENCODINGS = { "binary" => "base64" } unless defined?(DEFAULT_ENCODINGS)
TYPE_NAMES = { "Symbol" => "symbol", "Fixnum" => "integer", "Bignum" => "integer", "BigDecimal" => "decimal", "Float" => "float", "TrueClass" => "boolean", "FalseClass" => "boolean", "Date" => "date", "DateTime" => "datetime", "Time" => "datetime", "Array" => "array", "Hash" => "hash" } unless defined?(TYPE_NAMES)
FORMATTING = { "symbol" => Proc.new { |symbol| symbol.to_s }, "date" => Proc.new { |date| date.to_s(:db) }, "datetime" => Proc.new { |time| time.xmlschema }, "binary" => Proc.new { |binary| ::Base64.encode64(binary) }, "yaml" => Proc.new { |yaml| yaml.to_yaml }
PARSING = { "symbol" => Proc.new { |symbol| symbol.to_sym }, "date" => Proc.new { |date| ::Date.parse(date) }, "datetime" => Proc.new { |time| Time.xmlschema(time).utc rescue ::DateTime.parse(time).utc }, "integer" => Proc.new { |integer| integer.to_i }, "float" => Proc.new { |float| float.to_f }, "decimal" => Proc.new { |number| BigDecimal(number) }, "boolean" => Proc.new { |boolean| %w(1 true).include?(boolean.strip) }, "string" => Proc.new { |string| string.to_s }, "yaml" => Proc.new { |yaml| YAML::load(yaml) rescue yaml }, "base64Binary" => Proc.new { |bin| ::Base64.decode64(bin) }, "binary" => Proc.new { |bin, entity| _parse_binary(bin, entity) }, "file" => Proc.new { |file, entity| _parse_file(file, entity) }
Attributes
[R] backend
Instance Public methods
backend=(name)
    # File activesupport/lib/active_support/xml_mini.rb, line 82
82:     def backend=(name)
83:       if name.is_a?(Module)
84:         @backend = name
85:       else
86:         require "active_support/xml_mini/#{name.to_s.downcase}"
87:         @backend = ActiveSupport.const_get("XmlMini_#{name}")
88:       end
89:     end
rename_key(key, options = {})
     # File activesupport/lib/active_support/xml_mini.rb, line 130
130:     def rename_key(key, options = {})
131:       camelize  = options[:camelize]
132:       dasherize = !options.has_key?(:dasherize) || options[:dasherize]
133:       if camelize
134:         key = true == camelize ? key.camelize : key.camelize(camelize)
135:       end
136:       key = _dasherize(key) if dasherize
137:       key
138:     end
to_tag(key, value, options)
     # File activesupport/lib/active_support/xml_mini.rb, line 98
 98:     def to_tag(key, value, options)
 99:       type_name = options.delete(:type)
100:       merged_options = options.merge(:root => key, :skip_instruct => true)
101: 
102:       if value.is_a?(::Method) || value.is_a?(::Proc)
103:         if value.arity == 1
104:           value.call(merged_options)
105:         else
106:           value.call(merged_options, key.to_s.singularize)
107:         end
108:       elsif value.respond_to?(:to_xml)
109:         value.to_xml(merged_options)
110:       else
111:         type_name ||= TYPE_NAMES[value.class.name]
112:         type_name ||= value.class.name if value && !value.respond_to?(:to_str)
113:         type_name   = type_name.to_s   if type_name
114: 
115:         key = rename_key(key.to_s, options)
116: 
117:         attributes = options[:skip_types] || type_name.nil? ? { } : { :type => type_name }
118:         attributes[:nil] = true if value.nil?
119: 
120:         encoding = options[:encoding] || DEFAULT_ENCODINGS[type_name]
121:         attributes[:encoding] = encoding if encoding
122: 
123:         formatted_value = FORMATTING[type_name] && !value.nil? ?
124:           FORMATTING[type_name].call(value) : value
125: 
126:         options[:builder].tag!(key, formatted_value, attributes)
127:       end
128:     end
with_backend(name)
    # File activesupport/lib/active_support/xml_mini.rb, line 91
91:     def with_backend(name)
92:       old_backend, self.backend = backend, name
93:       yield
94:     ensure
95:       self.backend = old_backend
96:     end
Instance Protected methods
_dasherize(key)
     # File activesupport/lib/active_support/xml_mini.rb, line 142
142:     def _dasherize(key)
143:       # $2 must be a non-greedy regex for this to work
144:       left, middle, right = /\A(_*)(.*?)(_*)\Z/.match(key.strip)[1,3]
145:       "#{left}#{middle.tr('_ ', '--')}#{right}"
146:     end
_parse_file(file, entity)
     # File activesupport/lib/active_support/xml_mini.rb, line 158
158:     def _parse_file(file, entity)
159:       f = StringIO.new(::Base64.decode64(file))
160:       f.extend(FileLike)
161:       f.original_filename = entity['name']
162:       f.content_type = entity['content_type']
163:       f
164:     end