Sha256: b1243db3c5b7ba06e8744a29b1de90a12ca207b9ae2e99b8a5160db7fbf5271b
Contents?: true
Size: 1.74 KB
Versions: 2
Compression:
Stored size: 1.74 KB
Contents
# frozen_string_literal: true require 'dry/transformer/pipe/class_interface' module Dry module Transformer # Pipe class for defining transprocs with a class DSL. # # @example # require 'anima' # require 'dry/transformer/all' # # class User # include Anima.new(:name, :address) # end # # class Address # include Anima.new(:city, :street, :zipcode) # end # # class UsersMapper < Dry::Transformer::Pipe # 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">> # ] # # @api public class Pipe extend ClassInterface attr_reader :transproc # Execute the transformation pipeline with the given input. # # @example # # class SymbolizeKeys < Dry::Transformer # symbolize_keys # end # # SymbolizeKeys.new.call('name' => 'Jane') # # => {:name=>"Jane"} # # @param [mixed] input The input to pass to the pipeline # # @return [mixed] output The output returned from the pipeline # # @api public def call(input) transproc.call(input) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
dry-transformer-0.1.1 | lib/dry/transformer/pipe.rb |
dry-transformer-0.1.0 | lib/dry/transformer/pipe.rb |