Class: Wrest::Components::Mutators::XmlMiniTypeCaster

Inherits:
Base
  • Object
show all
Defined in:
lib/wrest/components/mutators/xml_mini_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 ActiveSupport::XmlMini

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)



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/wrest/components/mutators/xml_mini_type_caster.rb', line 18

def do_mutate(tuple)
  out_key, in_value = tuple

  case in_value
  when Hash
    if in_value['nil'] == 'true'
      out_value = nil
    elsif in_value.key?('type')
      caster = ActiveSupport::XmlMini::PARSING[in_value['type']]
      out_value = caster ? caster.call(in_value['__content__']) : in_value
    elsif in_value.key?('__content__')
      out_value = in_value['__content__']
    else
      out_value = in_value.mutate_using(self)
    end
  when Array
    out_value = in_value.collect{|hash| hash.mutate_using(self)}
  else
    out_value = in_value
  end

  [out_key, out_value]
end