The project is in a healthy, maintained state
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
 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 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

# db/migrate/20210227054155_create_users.rb
class CreateUsers < ActiveRecord::Migration[6.1]
  def change
    create_table :users do |t|
      t.string :name, null: false
      t.string :message, null: true
      t.integer :age, null: false
      t.integer :score
      t.boolean :premium
      t.timestamps
    end
    add_index  :users, [:age, :name], unique: true
  end
end

# app/models/user.rb
class User < ApplicationRecord

  validates :message, presence: true
  validates :age, numericality: true
  validates :score, presence: true, numericality: true, allow_nil: true
  validates :premium, presence: true
  validates_uniqueness_of :age, scope: :name
end

Development

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/spicy_validation. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

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

Code of Conduct

Everyone interacting in the SpicyValidation project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

Reference

https://github.com/sinsoku/pretty_validation