Module: Reforge::Transformation::DSL
- Included in:
- Reforge::Transformation
- Defined in:
- lib/reforge/transformation/dsl.rb
Instance Method Summary collapse
- #create_tree ⇒ Object
- #extract(path = nil, from:, memoize: nil) ⇒ Object
-
#transform(transform = nil, into: nil, memoize: nil, **transform_hash) ⇒ Object
TRICKY: we want to support e.g.
- #transform_definitions ⇒ Object
Instance Method Details
#create_tree ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/reforge/transformation/dsl.rb', line 34 def create_tree transform_definitions.each_with_object(Tree.new) do |transform_definition, tree| transform = Transform.new( transform_definition[:transform], memoize: transform_definition[:memoize] ) tree.attach_transform(*transform_definition[:path], transform) rescue StandardError => e raise TreeCreationError, "Failed to attach node at path #{[*transform_definition[:path]]} - #{e.}" end end |
#extract(path = nil, from:, memoize: nil) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/reforge/transformation/dsl.rb', line 8 def extract(path = nil, from:, memoize: nil) transform_definitions.push( { path: path, transform: from, memoize: memoize }.compact ) end |
#transform(transform = nil, into: nil, memoize: nil, **transform_hash) ⇒ Object
TRICKY: we want to support e.g. the following equivalent calls:
-
transform key: 0, into: [:foo, :bar]
-
transform ->(source) { source }, into: [:foo, :bar]
but in the former case the arguments are collapsed into a single hash which is used as the transform arg. By using **transform_hash we can avoid this behavior, but as a result the transform could be in either the transform argument or the transform_hash
24 25 26 27 28 29 30 31 32 |
# File 'lib/reforge/transformation/dsl.rb', line 24 def transform(transform = nil, into: nil, memoize: nil, **transform_hash) transform_definitions.push( { path: into, transform: transform || transform_hash, memoize: memoize }.compact ) end |
#transform_definitions ⇒ Object
46 47 48 |
# File 'lib/reforge/transformation/dsl.rb', line 46 def transform_definitions @transform_definitions ||= [] end |