Class: Transproc::Transformer

Inherits:
Object
  • Object
show all
Extended by:
ClassInterface, Deprecated::ClassInterface
Defined in:
lib/transproc/transformer.rb,
lib/transproc/transformer/dsl.rb,
lib/transproc/transformer/class_interface.rb,
lib/transproc/transformer/deprecated/class_interface.rb

Overview

Transfomer class for defining transprocs with a class DSL.

Examples:

require 'anima'
require 'transproc/all'

class User
  include Anima.new(:name, :address)
end

class Address
  include Anima.new(:city, :street, :zipcode)
end

class UsersMapper < Transproc::Transformer
  map_array do
    symbolize_keys
    rename_keys user_name: :name
    nest :address, %i(city street zipcode)
    map_value :address do
      constructor_inject Address
    end
    constructor_inject User
  end
end

UsersMapper.new.call(
  [
    { 'user_name' => 'Jane',
      'city' => 'NYC',
      'street' => 'Street 1',
      'zipcode' => '123'
    }
  ]
)
# => [
  #<User
    name="Jane"
    address=#<Address city="NYC" street="Street 1" zipcode="123">>
]

Defined Under Namespace

Modules: ClassInterface, Deprecated Classes: DSL

Instance Attribute Summary collapse

Attributes included from ClassInterface

#dsl

Instance Method Summary collapse

Methods included from ClassInterface

[], container, define!, import, inherited, new, t

Methods included from Deprecated::ClassInterface

define, inherited, method_missing, new, respond_to_missing?

Instance Attribute Details

#transprocObject (readonly)



53
54
55
# File 'lib/transproc/transformer.rb', line 53

def transproc
  @transproc
end

Instance Method Details

#call(input) ⇒ mixed

Execute the transformation pipeline with the given input.

Examples:


class SymbolizeKeys < Transproc::Transformer
  symbolize_keys
end

SymbolizeKeys.new.call('name' => 'Jane')
# => {:name=>"Jane"}

Parameters:

  • input (mixed)

    The input to pass to the pipeline

Returns:

  • (mixed)

    output The output returned from the pipeline



71
72
73
# File 'lib/transproc/transformer.rb', line 71

def call(input)
  transproc.call(input)
end