module Dry::Transformer::Pipe::ClassInterface
@api public
Attributes
dsl[R]
@api private
Public Instance Methods
[](container)
click to toggle source
Return a base Dry::Transformer
class with the container configured to the passed argument.
@example
class MyTransformer < Dry::Transformer[Transproc] end
@param [Transproc::Registry] container
The container to resolve transprocs from
@return [subclass of Dry::Transformer]
@api public
# File lib/dry/transformer/pipe/class_interface.rb, line 27 def [](container) klass = Class.new(self) klass.container(container) klass end
container(container = Undefined)
click to toggle source
Get or set the container to resolve transprocs from.
@example
# Setter Dry::Transformer.container(Transproc) # => Transproc # Getter Dry::Transformer.container # => Transproc
@param [Transproc::Registry] container
The container to resolve transprocs from
@return [Transproc::Registry]
@api private
# File lib/dry/transformer/pipe/class_interface.rb, line 60 def container(container = Undefined) if container.equal?(Undefined) @container ||= Module.new.extend(Dry::Transformer::Registry) else @container = container end end
define!(&block)
click to toggle source
@api public
# File lib/dry/transformer/pipe/class_interface.rb, line 74 def define!(&block) @dsl ||= DSL.new(container) @dsl.instance_eval(&block) self end
import(*args)
click to toggle source
@api public
# File lib/dry/transformer/pipe/class_interface.rb, line 69 def import(*args) container.import(*args) end
inherited(subclass)
click to toggle source
@api private
Calls superclass method
# File lib/dry/transformer/pipe/class_interface.rb, line 34 def inherited(subclass) super subclass.container(@container) if defined?(@container) subclass.instance_variable_set('@dsl', dsl.dup) if dsl end
new(*)
click to toggle source
@api public
Calls superclass method
# File lib/dry/transformer/pipe/class_interface.rb, line 81 def new(*) super.tap do |transformer| transformer.instance_variable_set('@transproc', dsl.(transformer)) if dsl end end
t(fn, *args)
click to toggle source
Get a transformation from the container, without adding it to the transformation pipeline
@example
class Stringify < Dry::Transformer map_values t(:to_string) end Stringify.new.call(a: 1, b: 2) # => {a: '1', b: '2'}
@param [Proc, Symbol] fn
A proc, a name of the module's own function, or a name of imported procedure from another module
@param [Object, Array] args
Args to be carried by the transproc
@return [Transproc::Function]
@api public
# File lib/dry/transformer/pipe/class_interface.rb, line 109 def t(fn, *args) container[fn, *args] end