Class: Wrest::Components::Mutators::XmlSimpleTypeCaster

Inherits:
Base
  • Object
show all
Defined in:
lib/wrest/components/mutators/xml_simple_type_caster.rb

Overview

This mutator undertands how do type casting using the type data embedded in a hash created by deserialising an xml using xml-simple

Instance Attribute Summary

Attributes inherited from Base

#next_mutator

Instance Method Summary (collapse)

Methods inherited from Base

inherited, #initialize, #mutate

Constructor Details

This class inherits a constructor from Wrest::Components::Mutators::Base

Instance Method Details

- (Object) do_mutate(tuple)



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/wrest/components/mutators/xml_simple_type_caster.rb', line 17

def do_mutate(tuple)
  out_key = tuple.first
  in_value = tuple.last[0]
  out_value = in_value

  case in_value
  when Hash
    if in_value['nil'] == 'true'
      out_value = nil
    elsif in_value.key?('type')
      out_value = ActiveSupport::XmlMini::PARSING[in_value['type']].call(in_value['content'])
    else
      out_value = in_value.mutate_using(self)
    end
  end

  [out_key, out_value]
end