Sha256: e60cbe8b62cd9828ee0fd230f25193202b6f4227ec9be05d6ddc002c40233eed

Contents?: true

Size: 450 Bytes

Versions: 72

Compression:

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

72 entries across 72 versions & 1 rubygems

Version Path
marty-1.2.9 app/models/marty/name_validator.rb
marty-1.2.8 app/models/marty/name_validator.rb
marty-1.2.7 app/models/marty/name_validator.rb
marty-1.2.6 app/models/marty/name_validator.rb
marty-1.2.5 app/models/marty/name_validator.rb
marty-1.2.4 app/models/marty/name_validator.rb
marty-1.2.3 app/models/marty/name_validator.rb
marty-1.2.2 app/models/marty/name_validator.rb
marty-1.2.1 app/models/marty/name_validator.rb
marty-1.2.0 app/models/marty/name_validator.rb
marty-1.1.9 app/models/marty/name_validator.rb
marty-1.1.8 app/models/marty/name_validator.rb
marty-1.1.7 app/models/marty/name_validator.rb
marty-1.1.6 app/models/marty/name_validator.rb
marty-1.1.5 app/models/marty/name_validator.rb
marty-1.1.4 app/models/marty/name_validator.rb
marty-1.1.3 app/models/marty/name_validator.rb
marty-1.1.2 app/models/marty/name_validator.rb
marty-1.1.1 app/models/marty/name_validator.rb
marty-1.0.54 app/models/marty/name_validator.rb