|
|
@ -9,6 +9,7 @@ class BulkUpload::Lettings::Validator |
|
|
|
attr_reader :bulk_upload, :path |
|
|
|
attr_reader :bulk_upload, :path |
|
|
|
|
|
|
|
|
|
|
|
validate :validate_file_not_empty |
|
|
|
validate :validate_file_not_empty |
|
|
|
|
|
|
|
validate :validate_min_columns |
|
|
|
validate :validate_max_columns |
|
|
|
validate :validate_max_columns |
|
|
|
|
|
|
|
|
|
|
|
def initialize(bulk_upload:, path:) |
|
|
|
def initialize(bulk_upload:, path:) |
|
|
@ -127,12 +128,20 @@ private |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def validate_min_columns |
|
|
|
|
|
|
|
return if halt_validations? |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
column_count = rows.map(&:size).min |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
errors.add(:base, :under_min_column_count) if column_count < csv_parser.class::MIN_COLUMNS |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def validate_max_columns |
|
|
|
def validate_max_columns |
|
|
|
return if halt_validations? |
|
|
|
return if halt_validations? |
|
|
|
|
|
|
|
|
|
|
|
column_count = rows.map(&:size).max |
|
|
|
column_count = rows.map(&:size).max |
|
|
|
|
|
|
|
|
|
|
|
errors.add(:file, :column_count) if column_count > csv_parser.class::MAX_COLUMNS |
|
|
|
errors.add(:base, :over_max_column_count) if column_count > csv_parser.class::MAX_COLUMNS |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def halt_validations! |
|
|
|
def halt_validations! |
|
|
|