Class: CsvRowModel::Import::ParsedModel::Model

Inherits:
OpenStruct
  • Object
show all
Includes:
ActiveWarnings
Defined in:
lib/csv_row_model/concerns/import/parsed_model.rb

Class Method Summary collapse

Class Method Details

.add_type_validation(column_name, options) ⇒ Object

Adds the type validation based on :validate_type option


59
60
61
62
63
64
# File 'lib/csv_row_model/concerns/import/parsed_model.rb', line 59

def add_type_validation(column_name, options)
  return unless options[:validate_type]

  type = options[:type]
  class_eval { validates column_name, :"#{type.to_s.underscore}_format" => true, allow_blank: true }
end

.custom_check_options(options) ⇒ Object

Raises:

  • (ArgumentError)

52
53
54
55
56
# File 'lib/csv_row_model/concerns/import/parsed_model.rb', line 52

def custom_check_options(options)
  return unless options[:validate_type]
  class_string = "#{options[:type].to_s.classify}FormatValidator"
  raise ArgumentError.new("with :validate_type and given :type of #{options[:type]}, the class #{class_string} must be defined") unless class_string.safe_constantize
end

.valid_optionsObject


48
49
50
# File 'lib/csv_row_model/concerns/import/parsed_model.rb', line 48

def valid_options
  %i[type validate_type]
end