GitXplorerGitXplorer
r

moderate

public
5 stars
0 forks
0 issues

Commits

List of commits on branch main.
Unverified
43d658c81532ea0fa3a05b0b0b1c85821115ba73

Improve README and Gemspec

rrameerez committed 2 months ago
Unverified
0452e2ed1209f0cb02f3c69eb44a429982cf4642

Update README

rrameerez committed 2 months ago
Unverified
4609f66c6510ead8deb4af8bd638a0f891b4767d

Add word list cache invalidation mechanism to refresh the word list after 30 days

rrameerez committed 2 months ago
Unverified
6269b613bea74278c03e4018205f4c767e7c334c

Implement actual bad word list download and caching

rrameerez committed 2 months ago
Unverified
814cd36ece0b6cee3c93b8f064203c082f9c8b3c

Implement basic functionality

rrameerez committed 2 months ago
Unverified
ce2e75c398fe4fcf314600bdc317bd195a34f2c3

Initial commit

rrameerez committed 2 months ago

README

The README file for this repository.

👮‍♂️ moderate - Block profanities in text fields

moderate is a Ruby gem that moderates user-generated text content by adding a simple validation to block bad words in any text field (profanities, cussing, swearing, obscenity, etc.)

Simply add this to your model:

validates :text_field, moderate: true

That's it! You're done. moderate will work seamlessly with your existing validations and error messages.

[!WARNING] This gem is under development. It currently only supports a limited set of English profanity words. Word matching is very basic now, and it may be prone to false positives, and false negatives. I use it for very simple things like preventing new submissions if they contain bad words, but the gem can be improved for more complex use cases and sophisticated matching and content moderation. Please consider contributing if you can improve the gem, or have good ideas for additional features.

Why

Any text field where users can input text may be a place where bad words can be used. This gem blocks records from being created if they contain bad words, profanity, naughty / obscene words, etc.

It's good for Rails applications where you need to maintain a clean and respectful environment in comments, posts, or any other user input.

How

moderate currently downloads a list of ~1k English profanity words from the google-profanity-words repository and caches it in your Rails app's tmp directory.

Installation

Add this line to your application's Gemfile:

gem 'moderate'

And then execute:

bundle install

Then, just add the moderate validation to any model with a text field:

validates :text_field, moderate: true

moderate will raise an error if a bad word is found in the text field, preventing the record from being saved.

It works seamlessly with your existing validations and error messages.

Configuration

You can configure the moderate gem behavior by adding a config/initializers/moderate.rb file:

Moderate.configure do |config|
  # Custom error message when bad words are found
  config.error_message = "contains inappropriate language"

  # Add your own words to the blacklist
  config.additional_words = ["badword1", "badword2"]

  # Exclude words from the default list (false positives)
  config.excluded_words = ["good"]
end

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/rameerez/moderate. Our code of conduct is: just be nice and make your mom proud of what you do and post online.

License

The gem is available as open source under the terms of the MIT License.