Module: Topographer::Importer::Mapper::MappingValidator

Included in:
MapperBuilder
Defined in:
lib/topographer/importer/mapper/mapping_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_key_field(field) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/topographer/importer/mapper/mapping_validator.rb', line 33

def validate_key_field(field)
  if field.is_a?(Array)
    raise Topographer::InvalidMappingError, 'One to many mapping is not supported'
  elsif key_fields.include?(field)
    raise Topographer::InvalidMappingError, "Field `#{field}` has already been included as a key"
  end
end

#validate_unique_column_mapping_type(mapping_input_columns, options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/topographer/importer/mapper/mapping_validator.rb', line 13

def validate_unique_column_mapping_type(mapping_input_columns, options = {})
  ignored = options.fetch(:ignored, false)
  mapping_input_columns = Array(mapping_input_columns)
  mapping_input_columns.each do |col|
    if ignored && ((input_columns + ignored_mapping_columns).include?(col))
      raise Topographer::InvalidMappingError, 'Input column already mapped to an output column.'
    elsif (ignored_mapping_columns.include?(col))
      raise Topographer::InvalidMappingError, 'Input column already ignored.'
    end
  end
end

#validate_unique_mapping(mapping_input_columns, output_field) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/topographer/importer/mapper/mapping_validator.rb', line 25

def validate_unique_mapping(mapping_input_columns, output_field)
  if (output_field.is_a?(Array))
    raise Topographer::InvalidMappingError, 'One to many mapping is not supported'
  end
  validate_unique_column_mapping_type(mapping_input_columns)
  validate_unique_output_mapping(output_field)
end

#validate_unique_output_mapping(output_field) ⇒ Object



7
8
9
10
11
# File 'lib/topographer/importer/mapper/mapping_validator.rb', line 7

def validate_unique_output_mapping(output_field)
  if output_fields.include?(output_field)
    raise Topographer::InvalidMappingError, 'Output column already mapped.'
  end
end

#validate_unique_validation_name(name) ⇒ Object



3
4
5
# File 'lib/topographer/importer/mapper/mapping_validator.rb', line 3

def validate_unique_validation_name(name)
  raise Topographer::InvalidMappingError, "A validation already exists with the name `#{name}`" if validation_mappings.has_key?(name)
end