根据数据库模式自动创建验证。
SchemaValidations is an ActiveRecord extension that keeps your model class definitions simpler and more DRY, by automatically defining validations based on the database schema.
One of the great things about Rails (ActiveRecord, in particular) is that it inspects the database and automatically defines accessors for all your columns, keeping your model class definitions simple and DRY. That's great for simple data columns, but where it falls down is when your table contains constraints.
create_table :users do |t|
t.string :email, null: false, limit: 30
t.boolean :confirmed, null: false
endIn that case the constraints null: false, limit: 30 and :boolean must be validated on the model level, to avoid ugly database exceptions:
class User true, :maximum=>50which shows the exact validation definition call.
SchemaValidations defines the validations lazily for each class, only creating them when they are needed (in order to validate a record of the class, or in response to introspection on the class). So you may need to search through the log file for "schema_validations" to find all the validations, and some classes' validations may not be defined at all if they were never needed for the logged use case.
As of version 1.2.0, SchemaValidations supports and is tested on:
Earlier versions of SchemaValidations supported:
SchemaValidations is derived from the "Red Hill On Rails" plugin schema_validations originally created by harukizaemon (https://github.com/harukizaemon)
SchemaValidations was created in 2011 by Michał Łomnicki and Ronen Barzel
Are you interested in contributing to schema_validations? Thanks! Please follow the standard protocol: fork, feature branch, develop, push, and issue pull request.
Some things to know about to help you develop and test:
schema_dev: SchemaValidations uses schema_dev to facilitate running rspec tests on the matrix of ruby, activerecord, and database versions that the gem supports, both locally and on github actions
To to run rspec locally on the full matrix, do:
$ schema_dev bundle install
$ schema_dev rspecYou can also run on just one configuration at a time; For info, see schema_dev --help or the schema_dev README.
The matrix of configurations is specified in schema_dev.yml in
the project root.
Code coverage results will be in coverage/index.html -- it should be at 100% coverage.
This gem is released under the MIT license.
暂无开放 Issues,或尚未同步最近议题。