Class: Serega::Validations::Attribute::CheckName

Inherits:
Object
  • Object
show all
Defined in:
lib/serega/validations/attribute/check_name.rb

Class Method Summary collapse

Class Method Details

.call(name) ⇒ void

This method returns an undefined value.

Checks allowed characters. Globally allowed characters: “a-z”, “A-Z”, “0-9”. Minus and low line “-”, “_” also allowed except as the first or last character.

Parameters:

  • name (String, Symbol)

    Attribute name

Raises:

  • (Error)

    when name has invalid format



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/serega/validations/attribute/check_name.rb', line 23

def call(name)
  name = name.to_s

  valid =
    case name.size
    when 0 then false
    when 1 then name.match?(FORMAT_ONE_CHAR)
    else name.match?(FORMAT_MANY_CHARS)
    end

  return if valid

  raise Error, message(name)
end