Class: DisjointLibraryFolderValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
app/validators/disjoint_library_folder_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



2
3
4
5
6
7
8
9
# File 'app/validators/disjoint_library_folder_validator.rb', line 2

def validate_each(record, attribute, value)
  return if value.nil?
  value.chomp!(File::SEPARATOR)
  # i18n-tasks-use t("activerecord.errors.models.library.attributes.path.cannot_contain")
  record.errors.add attribute, :cannot_contain if library_paths.any? { it.starts_with?(value + File::SEPARATOR) }
  # i18n-tasks-use t("activerecord.errors.models.library.attributes.path.cannot_be_contained")
  record.errors.add attribute, :cannot_be_contained if library_paths.any? { value.starts_with?(it + File::SEPARATOR) }
end