Sha256: 3410f0826ae0bd4ec88a8b5db623ee8c1f975a276c1687ff096bfabd4b60f3e2

Contents?: true

Size: 457 Bytes

Versions: 15

Compression:

Stored size: 457 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 /\A\s|\s\z|\A.*\s\s.*\z|.*\|.*/.match?(value)
      entry.errors[field] <<
        I18n.t('activerecord.errors.messages.extraneous_spaces')
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
marty-14.3.0 app/models/marty/name_validator.rb
marty-14.0.0 app/models/marty/name_validator.rb
marty-13.0.2 app/models/marty/name_validator.rb
marty-11.0.0 app/models/marty/name_validator.rb
marty-10.0.3 app/models/marty/name_validator.rb
marty-10.0.2 app/models/marty/name_validator.rb
marty-10.0.0 app/models/marty/name_validator.rb
marty-9.5.1 app/models/marty/name_validator.rb
marty-9.5.0 app/models/marty/name_validator.rb
marty-9.3.3 app/models/marty/name_validator.rb
marty-9.3.2 app/models/marty/name_validator.rb
marty-9.3.0 app/models/marty/name_validator.rb
marty-8.5.0 app/models/marty/name_validator.rb
marty-8.4.1 app/models/marty/name_validator.rb
marty-8.3.1 app/models/marty/name_validator.rb