Repository URL to install this package:
|
Version:
0.4.4 ▾
|
# frozen_string_literal: true
module Datasync
module DSL
# Implements the DSL for specifying field mappings
class MappingDSL
def initialize(source, old_target, new_target)
@source = source
@old_target = old_target || {}
@target_exists = !old_target.nil?
@target = new_target
end
attr_reader :old_target
def target_exists?
@target_exists
end
def map(**args)
args.each do |field, value|
@target[field] = value
end
end
def method_missing(name, *params, &block)
if source_shorthand?(name, *params, &block)
@source[name]
else
super
end
end
def respond_to_missing?(name, *)
source_shorthand?(name) || super
end
private
def source_shorthand?(name, *params, &block)
@source.key?(name) && params.empty? && !block
end
end
end
end