Class: PathValidator

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
app/validators/path_validator.rb

Instance Method Summary collapse

Instance Method Details

#match?(path) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
# File 'app/validators/path_validator.rb', line 8

def match?(path)
  # See if the applying path matches any reserved_paths via a Regex
  Landable.configuration.reserved_paths.any? { |reserved| Regexp.new("^#{reserved}$", 'i').match(path) }
end

#validate(record) ⇒ Object



2
3
4
5
6
# File 'app/validators/path_validator.rb', line 2

def validate(record)
  if match?(record.path)
    record.errors[:path] << "is Reserved!"
  end
end