Skip to content

Programmatic Changes

bellmyer edited this page Sep 13, 2010 · 1 revision

Table of Contents

  1. Home – Summary and Installation instructions
  2. Model Usage – How to include blacklist validation in your model
  3. Blacklist Syntax – How to setup your blacklist yaml files, with the various options
  4. Programmatic Changes – Changing your blacklists programmatically

A word of caution

Before you read about updating your blacklists programmatically, it’s important to understand that the application will be updating your yaml files. I chose not to store blacklists in the database to simplify the gem, and its usage by the developer. I wanted a yaml file so blacklists would be easy to edit by hand. But I also allow you to edit them from within the code. This means the YAML library will be reading and writing to the blacklist files. This may cause some YAML reformatting in the files themselves, but everything will still work.

More importantly, you’re not just applying changes to this session – it’s for the entire application.

How do I…?

Add a blacklist item

# with the default message
User.blacklist(:name, 'Veronica')

# with a custom message #
User.blacklist(:name, 'Stinky Pete', 'smells funny')

Modify a blacklist item’s message

This is the same as adding – if the blacklist value already exists, the error message will be updated.

Remove a blacklist item

User.unblacklist(:name, 'Stinky Pete')