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.



52
53
54
55
56
57
# File 'lib/transproc/transformer/deprecated/class_interface.rb', line 52

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:



44
45
46
47
48
# File 'lib/transproc/transformer/deprecated/class_interface.rb', line 44

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.



16
17
18
19
20
21
22
# File 'lib/transproc/transformer/deprecated/class_interface.rb', line 16

def inherited(subclass)
  super

  if transformations.any?
    subclass.instance_variable_set('@transformations', transformations.dup)
  end
end

#new(*args) ⇒ Object



9
10
11
12
13
# File 'lib/transproc/transformer/deprecated/class_interface.rb', line 9

def new(*args)
  super(*args).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)


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

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.



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

def transproc
  transformations.reduce(:>>)
end