Class: Dry::Transformer::Pipe::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/transformer/pipe/dsl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(container, ast: [], &block) ⇒ DSL

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 a new instance of DSL.



17
18
19
20
21
# File 'lib/dry/transformer/pipe/dsl.rb', line 17

def initialize(container, ast: [], &block)
  @container = container
  @ast = ast
  instance_eval(&block) if block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object (private)

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.



51
52
53
54
# File 'lib/dry/transformer/pipe/dsl.rb', line 51

def method_missing(meth, *args, &block)
  arg_nodes = *args.map { |a| [:arg, a] }
  ast << [:fn, (block ? [meth, [*arg_nodes, node(&block)]] : [meth, arg_nodes])]
end

Instance Attribute Details

#astObject (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.



14
15
16
# File 'lib/dry/transformer/pipe/dsl.rb', line 14

def ast
  @ast
end

#containerObject (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/dsl.rb', line 11

def container
  @container
end

Instance Method Details

#call(transformer) ⇒ 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
# File 'lib/dry/transformer/pipe/dsl.rb', line 34

def call(transformer)
  Compiler.new(container, transformer).(ast)
end

#dupObject

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.



29
30
31
# File 'lib/dry/transformer/pipe/dsl.rb', line 29

def dup
  self.class.new(container, ast: ast.dup)
end

#t(name, *args) ⇒ Object



24
25
26
# File 'lib/dry/transformer/pipe/dsl.rb', line 24

def t(name, *args)
  container[name, *args]
end