module Transproc::Transformer::Deprecated::ClassInterface

@api public

Public Instance Methods

build(&block)
Alias for: define
define(&block) click to toggle source

Define an anonymous transproc derived from given Transformer Evaluates block with transformations and returns initialized transproc. Does not mutate original Transformer

@example

class MyTransformer < Transproc::Transformer[MyContainer]
end

transproc = MyTransformer.define do
  map_values t(:to_string)
end
transproc.call(a: 1, b: 2)
# => {a: '1', b: '2'}

@yield Block allowing to define transformations. The same as class level DSL

@return [Function] Composed transproc

@api public

# File lib/transproc/transformer/deprecated/class_interface.rb, line 45
def define(&block)
  return transproc unless block_given?

  Class.new(Transformer[container]).tap { |klass| klass.instance_eval(&block) }.transproc
end
Also aliased as: build
inherited(subclass) click to toggle source

@api private

Calls superclass method
# File lib/transproc/transformer/deprecated/class_interface.rb, line 17
def inherited(subclass)
  super

  if transformations.any?
    subclass.instance_variable_set('@transformations', transformations.dup)
  end
end
method_missing(method, *args, &block) click to toggle source

@api private

Calls superclass method
# File lib/transproc/transformer/deprecated/class_interface.rb, line 53
def method_missing(method, *args, &block)
  super unless container.contain?(method)
  func = block ? t(method, *args, define(&block)) : t(method, *args)
  transformations << func
  func
end
new(*) click to toggle source

@api public

Calls superclass method
# File lib/transproc/transformer/deprecated/class_interface.rb, line 9
def new(*)
  super.tap do |transformer|
    transformer.instance_variable_set('@transproc', transproc) if transformations.any?
  end
end
respond_to_missing?(method, _include_private = false) click to toggle source

@api private

Calls superclass method
# File lib/transproc/transformer/deprecated/class_interface.rb, line 61
def respond_to_missing?(method, _include_private = false)
  super || container.contain?(method)
end
transproc() click to toggle source

@api private

# File lib/transproc/transformer/deprecated/class_interface.rb, line 66
def transproc
  transformations.reduce(:>>)
end

Private Instance Methods

transformations() click to toggle source

An array containing the transformation pipeline

@api private

# File lib/transproc/transformer/deprecated/class_interface.rb, line 75
def transformations
  @transformations ||= []
end