Class: Topographer::Importer::Mapper::ValidationFieldMapping
- Inherits:
-
FieldMapping
- Object
- FieldMapping
- Topographer::Importer::Mapper::ValidationFieldMapping
- Defined in:
- lib/topographer/importer/mapper/validation_field_mapping.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes inherited from FieldMapping
Instance Method Summary collapse
-
#initialize(name, input_columns, &validation_block) ⇒ ValidationFieldMapping
constructor
A new instance of ValidationFieldMapping.
- #process_input(input, result) ⇒ Object
- #required? ⇒ Boolean
Constructor Details
#initialize(name, input_columns, &validation_block) ⇒ ValidationFieldMapping
Returns a new instance of ValidationFieldMapping.
4 5 6 7 8 9 10 11 12 |
# File 'lib/topographer/importer/mapper/validation_field_mapping.rb', line 4 def initialize(name, input_columns, &validation_block) unless block_given? raise Topographer::InvalidMappingError, 'Validation fields must have a behavior block' end @name = name @input_columns = Array(input_columns) @validation_block = validation_block @output_field = nil end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
2 3 4 |
# File 'lib/topographer/importer/mapper/validation_field_mapping.rb', line 2 def name @name end |
Instance Method Details
#process_input(input, result) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/topographer/importer/mapper/validation_field_mapping.rb', line 14 def process_input(input, result) mapping_input = input.slice(*input_columns) @invalid_keys = get_invalid_keys(mapping_input) if @invalid_keys.blank? @validation_block.(mapping_input) else result.add_error(name, invalid_input_error) end rescue => exception result.add_error(name, exception.) end |
#required? ⇒ Boolean
28 29 30 |
# File 'lib/topographer/importer/mapper/validation_field_mapping.rb', line 28 def required? true end |