Class: BlacklistValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/blacklist_validator.rb

Instance Method Summary collapse

Instance Method Details

#blacklistObject

Lazy load and transform directly words to patterns instead of creating regexps at each matching tests



10
11
12
# File 'lib/blacklist_validator.rb', line 10

def blacklist
  @blacklist ||= YAML.load_file(blacklist_file).map { |word| /(#{word})+/i }
end

#validate_each(record, attribute, value) ⇒ Object



5
6
7
# File 'lib/blacklist_validator.rb', line 5

def validate_each(record, attribute, value)
  record.errors.add(attribute, options[:message] || invalid_message(record, attribute)) if blacklisted?(value)
end