Repository is archived
No release in over a year
SpicyValidation overwrite model file that user would like to generate validation.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
>= 0

Runtime

>= 0
 Project Readme

SpicyValidation

Generate validation methods automatically from database schema.

[important notice] Your model file will be overwritten!

Installation

Add this line to your application's Gemfile:

gem 'spicy_validation'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install spicy_validation

Usage

  1. Run validation:generate task
  2. Type a number that you would like to generate validation
% rails validation:generate
[warning] If you generate validation, model files will be overwritten.
{:"0"=>"samples", :"1"=>"users"}
Type a number you wanna generate validation > ex) 0

Example

+------------+--------------+------+-----+---------+----------------+
| Field      | Type         | Null | Key | Default | Extra          |
+------------+--------------+------+-----+---------+----------------+
| id         | bigint(20)   | NO   | PRI | NULL    | auto_increment |
| name       | varchar(255) | NO   |     | NULL    |                |
| message    | varchar(255) | YES  |     | NULL    |                |
| age        | int(11)      | NO   |     | NULL    |                |
| score      | int(11)      | YES  |     | NULL    |                |
| premium    | tinyint(1)   | YES  |     | NULL    |                |
| created_at | datetime(6)  | NO   |     | NULL    |                |
| updated_at | datetime(6)  | NO   |     | NULL    |                |
+------------+--------------+------+-----+---------+----------------+
# app/models/user.rb
class User < ApplicationRecord
  validates :name, presence: true
  validates :age, presence: true, numericality: true
  validates :score, numericality: true, allow_nil: true
end

License

The gem is available as open source under the terms of the MIT License.

Acknowledgement

This repository based on https://github.com/sinsoku/pretty_validation. See the file headers for detail informations.