Module: Dry::Transformer::Pipe::ClassInterface
- Included in:
- Dry::Transformer::Pipe
- Defined in:
- lib/dry/transformer/pipe/class_interface.rb
Instance Attribute Summary collapse
- #dsl ⇒ Object readonly private
Instance Method Summary collapse
-
#[](container) ⇒ subclass of Dry::Transformer
Return a base Dry::Transformer class with the container configured to the passed argument.
-
#container(container = Undefined) ⇒ Transproc::Registry
private
Get or set the container to resolve transprocs from.
- #define!(&block) ⇒ Object
- #import(*args) ⇒ Object
- #inherited(subclass) ⇒ Object private
- #new ⇒ Object
-
#t(fn, *args) ⇒ Transproc::Function
Get a transformation from the container, without adding it to the transformation pipeline.
Instance Attribute Details
#dsl ⇒ Object (readonly)
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.
11 12 13 |
# File 'lib/dry/transformer/pipe/class_interface.rb', line 11 def dsl @dsl end |
Instance Method Details
#[](container) ⇒ subclass of Dry::Transformer
Return a base Dry::Transformer class with the container configured to the passed argument.
27 28 29 30 31 |
# File 'lib/dry/transformer/pipe/class_interface.rb', line 27 def [](container) klass = Class.new(self) klass.container(container) klass end |
#container(container = 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.
60 61 62 63 64 65 66 |
# File 'lib/dry/transformer/pipe/class_interface.rb', line 60 def container(container = Undefined) if container.equal?(Undefined) @container ||= Module.new.extend(Dry::Transformer::Registry) else @container = container end end |
#define!(&block) ⇒ Object
74 75 76 77 78 |
# File 'lib/dry/transformer/pipe/class_interface.rb', line 74 def define!(&block) @dsl ||= DSL.new(container) @dsl.instance_eval(&block) self end |
#import(*args) ⇒ Object
69 70 71 |
# File 'lib/dry/transformer/pipe/class_interface.rb', line 69 def import(*args) container.import(*args) 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.
34 35 36 37 38 39 40 |
# File 'lib/dry/transformer/pipe/class_interface.rb', line 34 def inherited(subclass) super subclass.container(@container) if defined?(@container) subclass.instance_variable_set("@dsl", dsl.dup) if dsl end |
#new ⇒ Object
81 82 83 84 85 |
# File 'lib/dry/transformer/pipe/class_interface.rb', line 81 def new(*) super.tap do |transformer| transformer.instance_variable_set("@transproc", dsl.(transformer)) if dsl end end |
#t(fn, *args) ⇒ Transproc::Function
Get a transformation from the container, without adding it to the transformation pipeline
109 110 111 |
# File 'lib/dry/transformer/pipe/class_interface.rb', line 109 def t(fn, *args) container[fn, *args] end |