Skip to content
Validate your model against databse rules you’ve already created in your schema
Ruby

README.rdoc

Enforce Schema Rules

This plugin provides a way to validate your model against database rules you've already created in your schema, including column lengths for strings, “not null” designations, unique index constraints, and ensuring integer input for integer columns.

The four methods currently supported are:

enforce_column_limits
enforce_integer_columns
enforce_not_null
enforce_unique_indexes

You can also just call enforce_schema_rules to enforce all the above.

Accepts the relevant validates_length_of options (i.e. :on and :message) and these assume the usual defaults.

In addition to the regular options, you can also have an :except list enumerating the column that you don't want to validate.

By default, magic columns (_at, _on, _id, id, position, etc) are skipped. If you'd like to override that behavior, you can define your own :exclusion_regexp

Examples:

class Person < ActiveRecord::Base
  enforce_schema_rules :except => :dhh
end
class Book < ActiveRecord::Base
  enforce_column_limits :message => "exceeds the %d character limit", :on => :update
  enforce_unique_indexes
  enforce_not_null :exclusion_regexp => /$fk_/
end

Download

Development is done at:

http://github.com/twinge/enforce_schema_rules

You can install as a gem with:

gem install enforce_schema_rules

Bugs & feedback

Please send bug reports, patches and feedback to the GitHub project.

Credit

The plugin was written by Josh Starcher <josh.starcher@gmail.com>. It was updated to Rails 3 by Eric Anderson <eric@pixelwareinc.com>. This plugin is basically an extension of David Easley's enforce-limits plugin. Michael Schuerig provided contributed a patch and a style lesson.

Something went wrong with that request. Please try again.