Module: Transproc::Transformer::Deprecated::ClassInterface

Included in:
Transproc::Transformer
Defined in:
lib/transproc/transformer/deprecated/class_interface.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



53
54
55
56
57
58
# 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

Instance Method Details

#define { ... } ⇒ Function Also known as: build

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

Examples:


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'}

Yields:

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

Returns:



45
46
47
48
49
# 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

#inherited(subclass) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



17
18
19
20
21
22
23
# 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

#newObject



9
10
11
12
13
# 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) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


61
62
63
# File 'lib/transproc/transformer/deprecated/class_interface.rb', line 61

def respond_to_missing?(method, _include_private = false)
  super || container.contain?(method)
end

#transprocObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



66
67
68
# File 'lib/transproc/transformer/deprecated/class_interface.rb', line 66

def transproc
  transformations.reduce(:>>)
end