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
-
#[](container) ⇒ subclass of Transproc::Transformer
Return a base Transproc::Transformer class with the container configured to the passed argument.
-
#container(container = ::Transproc::Undefined) ⇒ Transproc::Registry
private
Get or set the container to resolve transprocs from.
-
#define { ... } ⇒ Function
(also: #build)
Define an anonymous transproc derived from given Transformer Evaluates block with transformations and returns initialized transproc.
- #inherited(subclass) ⇒ Object private
- #method_missing(method, *args, &block) ⇒ Object private
- #respond_to_missing?(method, _include_private = false) ⇒ Boolean private
-
#t(fn, *args) ⇒ Transproc::Function
Get a transformation from the container, without adding it to the transformation pipeline.
- #transproc ⇒ Object private
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.
110 111 112 113 114 115 116 117 |
# File 'lib/transproc/transformer/class_interface.rb', line 110 def method_missing(method, *args, &block) if container.contain?(method) args.push(define(&block)) if block_given? transformations << t(method, *args) 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.
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.
48 49 50 51 52 53 54 55 |
# File 'lib/transproc/transformer/class_interface.rb', line 48 def container(container = ::Transproc::Undefined) if container == ::Transproc::Undefined ensure_container_presence! @container else @container = container end end |
#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
77 78 79 80 81 |
# File 'lib/transproc/transformer/class_interface.rb', line 77 def define(&block) return transproc unless block_given? Class.new(self).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.
26 27 28 |
# File 'lib/transproc/transformer/class_interface.rb', line 26 def inherited(subclass) subclass.container(@container) if defined?(@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.
120 121 122 |
# File 'lib/transproc/transformer/class_interface.rb', line 120 def respond_to_missing?(method, _include_private = false) container.contain?(method) || super end |
#t(fn, *args) ⇒ Transproc::Function
Get a transformation from the container, without adding it to the transformation pipeline
105 106 107 |
# File 'lib/transproc/transformer/class_interface.rb', line 105 def t(fn, *args) container[fn, *args] end |
#transproc ⇒ 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.
125 126 127 |
# File 'lib/transproc/transformer/class_interface.rb', line 125 def transproc transformations.reduce(:>>) end |