Sha256: 94c4b4625cad1417fb0d4d99a6ed97f62e99184c77a70aeb6d841abf291034d7

Contents?: true

Size: 452 Bytes

Versions: 36

Compression:

Stored size: 452 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

36 entries across 36 versions & 1 rubygems

Version Path
marty-2.7.0 app/models/marty/name_validator.rb
marty-2.6.8 app/models/marty/name_validator.rb
marty-2.6.7 app/models/marty/name_validator.rb
marty-2.6.6 app/models/marty/name_validator.rb
marty-2.6.5 app/models/marty/name_validator.rb
marty-2.6.4 app/models/marty/name_validator.rb
marty-2.6.3 app/models/marty/name_validator.rb
marty-2.6.2 app/models/marty/name_validator.rb
marty-2.6.1 app/models/marty/name_validator.rb
marty-2.6.0 app/models/marty/name_validator.rb
marty-2.5.9 app/models/marty/name_validator.rb
marty-2.5.8 app/models/marty/name_validator.rb
marty-2.5.7 app/models/marty/name_validator.rb
marty-2.5.6 app/models/marty/name_validator.rb
marty-2.5.5 app/models/marty/name_validator.rb
marty-2.5.4 app/models/marty/name_validator.rb