Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
uoy-faculty-datasync / lib / datasync / dsl / mapping_dsl.rb
Size: Mime:
# 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