Module: Reforge::Transformation::Transform::Factories

Included in:
Reforge::Transformation::Transform
Defined in:
lib/reforge/transformation/transform/factories.rb

Constant Summary collapse

TRANSFORM_PROC_FACTORIES =

TODO: here we code to the least common denominator: everything is a proc. This likely works slower than something specialized to each individual case. This could be of concern since these will be called per-transform, per-source

{
  attribute: ->(attributes, **config) { attribute_transform_for(attributes, **config) },
  key: ->(keys, **config) { key_transform_for(keys, **config) },
  value: ->(value, **_config) { value_transform_for(value) }
}.freeze
TRANSFORM_TYPES =
TRANSFORM_PROC_FACTORIES.keys.freeze

Instance Method Summary collapse

Instance Method Details

#transform_proc_from(config) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/reforge/transformation/transform/factories.rb', line 17

def transform_proc_from(config)
  validate_config!(config)

  type = config.keys.detect { |key| TRANSFORM_TYPES.include?(key) }
  args = config[type]
  config = config.reject { |k, _v| k == type }

  TRANSFORM_PROC_FACTORIES[type].call(args, **config)
end