Class Wrest::Components::Mutators::XmlMiniTypeCaster

  1. lib/wrest/components/mutators/xml_mini_type_caster.rb
Parent: Mutators::Base

This mutator undertands how do type casting using the type data embedded in a hash created by deserialising an xml using ActiveSupport::XmlMini

Methods

public instance

  1. do_mutate

Public instance methods

do_mutate (tuple)
[show source]
    # File lib/wrest/components/mutators/xml_mini_type_caster.rb, line 18
18:       def do_mutate(tuple)
19:         out_key, in_value = tuple
20: 
21:         case in_value
22:         when Hash
23:           if in_value['nil'] == 'true'
24:             out_value = nil
25:           elsif in_value.key?('type')
26:             caster = ActiveSupport::XmlMini::PARSING[in_value['type']]
27:             out_value = caster ? caster.call(in_value['__content__']) : in_value
28:           elsif in_value.key?('__content__')
29:             out_value = in_value['__content__']
30:           else
31:             out_value = in_value.mutate_using(self)
32:           end
33:         when Array
34:           out_value = in_value.collect{|hash| hash.mutate_using(self)}
35:         else
36:           out_value = in_value
37:         end
38: 
39:         [out_key, out_value]
40:       end