Class: BlacklistValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- BlacklistValidator
- Defined in:
- lib/blacklist_validator.rb
Instance Method Summary collapse
-
#blacklist ⇒ Object
Lazy load and transform directly words to patterns instead of creating regexps at each matching tests.
- #validate_each(record, attribute, value) ⇒ Object
Instance Method Details
#blacklist ⇒ Object
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, [:message] || (record, attribute)) if blacklisted?(value) end |