Class: NamespaceValidator

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

Constant Summary collapse

NAMESPACE_MAX_LENGTH =
16
NAMESPACE_MIN_LENGTH =
1

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, val) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/models/validators/namespace_validator.rb', line 5

def validate_each(record, attribute, val)
  if !val
    record.errors.add(attribute, {:message => "Namespace is required and cannot be blank.", :exit_code => 106})
  elsif val and val.length < NAMESPACE_MIN_LENGTH
    record.errors.add(attribute, {:message => "Namespace is too short.  Minimum length is #{NAMESPACE_MIN_LENGTH} characters.", :exit_code => 106})
  elsif val and val.length > NAMESPACE_MAX_LENGTH
    record.errors.add(attribute, {:message => "Namespace is too long.  Maximum length is #{NAMESPACE_MAX_LENGTH} characters.", :exit_code => 106})
  elsif val and !(val =~ /\A[A-Za-z0-9]+\z/)
    record.errors.add(attribute, {:message => "Invalid namespace. Namespace must only contain alphanumeric characters.", :exit_code => 106})
  elsif val and OpenShift::ApplicationContainerProxy.blacklisted? val
    record.errors.add(attribute, {:message => "Namespace is not allowed.  Please choose another.", :exit_code => 106})
  end
end