Module: Bureaucrat::Validators

Defined in:
lib/bureaucrat/validators.rb

Defined Under Namespace

Classes: BaseValidator, MaxLengthValidator, MaxValueValidator, MinLengthValidator, MinValueValidator, RegexValidator

Constant Summary collapse

ValidateInteger =
lambda do |value|
  begin
    Integer(value)
  rescue ArgumentError
    raise ValidationError.new('')
  end
end
EMAIL_RE =

Original from Django’s EmailField: email_re = re.compile(

r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*"  # dot-atom
r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-\011\013\014\016-\177])*"' # quoted-string
r')@(?:[A-Z0-9]+(?:-*[A-Z0-9]+)*\.)+[A-Z]{2,6}$', re.IGNORECASE)  # domain
/
    (^[-!#\$%&'*+\/=?^_`{}|~0-9A-Z]+(\.[-!#\$%&'*+\/=?^_`{}|~0-9A-Z]+)*
    |^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-\011\013\014\016-\177])*"
    )@(?:[A-Z0-9]+(?:-*[A-Z0-9]+)*\.)+[A-Z]{2,6}$
/xi
ValidateEmail =
RegexValidator.new(regex: EMAIL_RE,
message: 'Enter a valid e-mail address.')
SLUG_RE =
/^[-\w]+$/
ValidateSlug =
RegexValidator.new(regex: SLUG_RE,
message: "Enter a valid 'slug' consisting of letters, numbers, underscores or hyphens.")
IPV4_RE =
/^(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}$/
IPV4Validator =
RegexValidator.new(regex: IPV4_RE,
message: 'Enter a valid IPv4 address.')
COMMA_SEPARATED_INT_LIST_RE =
/^[\d,]+$/
ValidateCommaSeparatedIntegerList =
RegexValidator.new(regex: COMMA_SEPARATED_INT_LIST_RE,
message: 'Enter only digits separated by commas.',
code: :invalid)

Class Method Summary collapse

Class Method Details

.empty_value?(value) ⇒ Boolean

Returns:

  • (Boolean)


3
4
5
# File 'lib/bureaucrat/validators.rb', line 3

def empty_value?(value)
  value.nil? || value == '' || value == [] || value == {}
end