Sha256: 04f9b938bb51810bccc1cbf44ad3ccc0db4330b217d2c0a56c3c5e4f92d039b7

Contents?: true

Size: 451 Bytes

Versions: 43

Compression:

Stored size: 451 Bytes

Contents

class Marty::NameValidator < ActiveModel::Validator
  def validate(entry)
    raise "need field option" unless options[:field]
    field = options[:field].to_sym
    value = entry.send(field)

    return if value.nil?

    # disallow leading, trailing, >1 internal spaces, special chars (|)
    if value =~ /\A\s|\s\z|\A.*\s\s.*\z|.*\|.*/
      entry.errors[field] <<
        I18n.t("activerecord.errors.messages.extraneous_spaces")
    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
marty-2.5.2 app/models/marty/name_validator.rb
marty-2.5.1 app/models/marty/name_validator.rb
marty-2.5.0 app/models/marty/name_validator.rb
marty-2.4.9 app/models/marty/name_validator.rb
marty-2.4.8 app/models/marty/name_validator.rb
marty-2.4.7 app/models/marty/name_validator.rb
marty-2.4.6 app/models/marty/name_validator.rb
marty-2.4.5 app/models/marty/name_validator.rb
marty-2.4.4 app/models/marty/name_validator.rb
marty-2.4.3 app/models/marty/name_validator.rb
marty-2.4.2 app/models/marty/name_validator.rb
marty-2.4.1 app/models/marty/name_validator.rb
marty-2.4.0 app/models/marty/name_validator.rb
marty-2.3.15 app/models/marty/name_validator.rb
marty-2.3.14 app/models/marty/name_validator.rb
marty-2.3.13 app/models/marty/name_validator.rb
marty-2.3.12 app/models/marty/name_validator.rb
marty-2.3.11 app/models/marty/name_validator.rb
marty-2.3.10 app/models/marty/name_validator.rb
marty-2.3.9 app/models/marty/name_validator.rb