View on GitHub

Daily affirmation

A simple library for external validations of POROs

Download this project as a .zip file Download this project as a tar.gz file


Codeship Status for teamsnap/daily_affirmation

Gem Version Code Climate Coverage Status Dependency Status License


A simple library for external validations of POROs

Daily Affirmation

There are currently two ways to validate objects in Rails, ActiveRecord based validates and ActiveModel based validations. Both require them to be placed directly into your models, making for more heavy weight, less flexible code. DailyAffirmation allows you to validate your models (or any PORO) externally.

By validating objects externally, you can have different validations depending on your code path. Perhaps you require a password for a User object when it's being created, but do not need it again when it's being updated. Simply create a UserCreationAffirmation and a UserChangeAffirmation with the correct validations.


Add this line to your application's Gemfile:

gem 'daily_affirmation'

And then execute:

$ bundle

Or install it yourself as:

$ gem install daily_affirmation


require "daily_affirmations"

class Team
  attr_accessor :name, :status_cd

class TeamAffirmation
  include DailyAffirmation.affirmations

  affirms_presence_of :name
  affirms_inclusion_of :status_cd, :list => 0..2

team1 = => "", :status_cd => 3) #=> false


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