Class: PathTemplateValidator

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

Constant Summary collapse

VALID_TOKENS =
[
  "tags",
  "creator",
  "collection",
  "collections",
  "modelName",
  "modelId"
]

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'app/validators/path_template_validator.rb', line 11

def validate_each(record, attribute, value)
  tokens = value.scan(/\{([a-zA-Z]+)\}/).flatten
  tokens.each do |token|
    unless token.in? VALID_TOKENS
      record.errors.add attribute, :invalid
      break
    end
  end
end