mirror of
https://github.com/manyfold3d/manyfold.git
synced 2026-10-22 03:32:18 -05:00
15 lines
531 B
Ruby
15 lines
531 B
Ruby
class DisjointLibraryFolderValidator < ActiveModel::EachValidator
|
|
def validate_each(record, attribute, value)
|
|
return if value.nil?
|
|
value.chomp!(File::SEPARATOR)
|
|
record.errors.add attribute, :cannot_contain if library_paths.any? { |it| it.starts_with?(value + File::SEPARATOR) }
|
|
record.errors.add attribute, :cannot_be_contained if library_paths.any? { |it| value.starts_with?(it + File::SEPARATOR) }
|
|
end
|
|
|
|
private
|
|
|
|
def library_paths
|
|
Library.pluck(:path) # rubocop:disable Pundit/UsePolicyScope
|
|
end
|
|
end
|