Module Wrest::Components::Mutators

  1. lib/wrest/components/mutators.rb

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


public class

  1. chain


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

Public class methods

chain (*mutator_keys)

Makes referencing and chaining mutators easy.


Mutators.chain(:xml_mini_type_caster, :camel_to_snake_case)

is equivalent to
[show source]
    # File lib/wrest/components/mutators.rb, line 26
26:       def self.chain(*mutator_keys)
27:         mutator_key = mutator_keys.pop
28:         mutator_keys.reverse.inject(REGISTRY[mutator_key].new) do |next_instance, next_key| 
29:           REGISTRY[next_key].new(next_instance)
30:         end
31:       end