Module: Wrest::Components::Mutators

Defined in:
lib/wrest/components/mutators.rb

Overview

A mutator understands how to transform one tuple(key/value pair) from a hash into another

Defined Under Namespace

Classes: Base, CamelToSnakeCase, XmlMiniTypeCaster, XmlSimpleTypeCaster

Constant Summary

REGISTRY =

All sublasses of Mutators::Base are automatically registered here by underscored, symbolised class name.

{}

Class Method Summary (collapse)

Class Method Details

+ (Object) chain(*mutator_keys)

Makes referencing and chaining mutators easy.

Example:

Mutators.chain(:xml_mini_type_caster, :camel_to_snake_case)

is equivalent to

Wrest::Components::Mutators::XmlMiniTypeCaster.new(Wrest::Components::Mutators::CamelToSnakeCase.new)


26
27
28
29
30
31
# File 'lib/wrest/components/mutators.rb', line 26

def self.chain(*mutator_keys)
  mutator_key = mutator_keys.pop
  mutator_keys.reverse.inject(REGISTRY[mutator_key].new) do |next_instance, next_key| 
    REGISTRY[next_key].new(next_instance)
  end
end