OptOut is a rubygem for tracking unsubscriptions to newsletters.


OptOut.unsubscribe('newsletters', '5')  # unsubscribe user id '5' from 'newsletters'
OptOut.subscribed?('newsletters', '5')
=> false

OptOut.subscribe('newsletters', '5')  # re-subscribe a user to 'newsletters'
OptOut.subscribed?('newsletters', '5')
=> true

OptOut.unsubscribed?('newsletters', '5')  # another way to query
=> false

OptOut.subscribed('newsletters', '8')  # users are subscribed by default unless explicitly unsubscribed
=> true

['1', '2', '3'].each {|user_id| OptOut.unsubscribe('newsletters', user_id)}
OptOut.unsubscribers  # returns a list of unsubscribed user ids
=> ['1', '2', '3']


The persistence backend can be configured to be one of:

For example, to configure OptOut to store unsubscriptions in Redis:

OptOut.configure do |c|
  c.adapter = OptOut::Adapters::RedisAdapter
  c.options = {
    :url => 'redis://localhost:6379'

See individual adapter classes for setup and configuration options. To write a custom adapter, take a look at AbstractAdapter


To run tests, you will need a running redis instance. Add a .env file to the project root to configure where redis lives:


To run tests:

$ rake


  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request