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