Module: Transproc::Transformer::ClassInterface Private

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

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

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.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/transproc/transformer/class_interface.rb', line 57

def method_missing(method, *args, &block)
  if container.functions.has_key?(method)
    if block_given?
      transformations << container[
        method,
        *args,
        create(container, &block).transproc
      ]
    else
      transformations << container[method, *args]
    end
  else
    super
  end
end

Instance Method Details

#[](container) ⇒ subclass of Transproc::Transformer

Return a base Transproc::Transformer class with the container configured to the passed argument.

Examples:


class MyTransformer < Transproc::Transformer[Transproc]
end

Parameters:

Returns:



19
20
21
22
23
# File 'lib/transproc/transformer/class_interface.rb', line 19

def [](container)
  klass = Class.new(Transformer)
  klass.container(container)
  klass
end

#container(container = ::Transproc::Undefined) ⇒ Transproc::Registry

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.

Get or set the container to resolve transprocs from.

Examples:


# Setter
Transproc::Transformer.container(Transproc)
# => Transproc

# Getter
Transproc::Transformer.container
# => Transproc

Parameters:

  • container (Transproc::Registry) (defaults to: ::Transproc::Undefined)

    The container to resolve transprocs from

Returns:



48
49
50
51
52
53
54
# File 'lib/transproc/transformer/class_interface.rb', line 48

def container(container = ::Transproc::Undefined)
  if container == ::Transproc::Undefined
    @container
  else
    @container = container
  end
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.



26
27
28
# File 'lib/transproc/transformer/class_interface.rb', line 26

def inherited(subclass)
  subclass.container(container)
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)


74
75
76
# File 'lib/transproc/transformer/class_interface.rb', line 74

def respond_to_missing?(method, _include_private = false)
  container.functions.has_key?(method) || super
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.



79
80
81
# File 'lib/transproc/transformer/class_interface.rb', line 79

def transproc
  transformations.reduce(:>>)
end