{"id":20061677,"url":"https://github.com/tylerrick/activemodel-validators","last_synced_at":"2025-09-12T00:45:38.756Z","repository":{"id":3115421,"uuid":"4142107","full_name":"TylerRick/activemodel-validators","owner":"TylerRick","description":"Some reusable ActiveModel validations, including greater_than, boolean_presence, and at_least_one_present","archived":false,"fork":false,"pushed_at":"2022-03-18T21:41:08.000Z","size":33,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T01:24:00.601Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TylerRick.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-04-25T22:41:43.000Z","updated_at":"2025-02-26T21:17:55.000Z","dependencies_parsed_at":"2022-08-30T06:25:19.331Z","dependency_job_id":null,"html_url":"https://github.com/TylerRick/activemodel-validators","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TylerRick%2Factivemodel-validators","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TylerRick%2Factivemodel-validators/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TylerRick%2Factivemodel-validators/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TylerRick%2Factivemodel-validators/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TylerRick","download_url":"https://codeload.github.com/TylerRick/activemodel-validators/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252533712,"owners_count":21763644,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T13:21:27.830Z","updated_at":"2025-05-05T16:30:46.519Z","avatar_url":"https://github.com/TylerRick.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"ActiveModel Validators\n=======================\n\nA collection of Rails ActiveModel Validators\n\nExample Usage\n-------------\n\n```ruby\nclass Thing \u003c ActiveRecord::Base\n  validates :birthdate, greater_than: { value: Date.new(1900), message: 'must be later than 1900' }\n  validates :birthdate, less_than:    { value: Time.zone.now.years_ago(1).to_date+1, message: 'must be at least 1 year ago' }\n  validates :end_date,  greater_than: { attr: :begin_date, operator_text: 'later than' }\n\n  # shortcut for        greater_than: { value: 1, operator: :\u003e= }\n  validates :how_many_pies, at_least: { value: 1 }\n\n  # shortcut for less_or_greater_than: { attr: :how_many_people, operator: :== }\n  validates :how_many_gifts, equal_to: { attr: :how_many_people }\n\n  # Because presence: true doesn't work for boolean attributes!\n  validates :is_18_or_older, boolean_presence: true\n\n  validates :model,  restrict_to: {allowed_options: ['Model A', 'Model B']}, allow_blank: true\n\n  validates_with AtLeastOnePresentValidator, at_least_one_of: [:home_phone, :work_phone]\n  validates_with AtLeastOnePresentValidator, at_least_one_of: [:parent_1_home_phone, :parent_1_work_phone, :parent_1_mobile_phone], message: :at_least_one_phone_parent_1\n\n  validates :option_b, blank: {message: :must_be_blank_if_option_a}, if: :option_a?\n\n  validates :rating, multiple_of: {of: '0.5'}\n\n  validates :total_profit, sum_of: { attr_names: (1..4).map {|quarter| :\"total_profit_q#{quarter}\" } }\n\n  validates :end_date, date: {required: true}\n  validates :graduation_year,       year: true\n\n  validates :address_postal_code,   postal_code: true\n  validates :address_state,         address_state: true\nend\n```\n\nDocumentation\n-------------\n\n* [GreaterThanValidator](activemodel-validators/blob/master/lib/activemodel-validators/greater_than_validator.rb)\n* [LessOrGreaterThanValidator](activemodel-validators/blob/master/lib/activemodel-validators/less_or_greater_than_validator.rb)\n* [LessThanValidator](activemodel-validators/blob/master/lib/activemodel-validators/less_than_validator.rb)\n* [AtLeastValidator](activemodel-validators/blob/master/lib/activemodel-validators/at_least_validator.rb)\n\n* [BooleanPresenceValidator](activemodel-validators/blob/master/lib/activemodel-validators/boolean_presence_validator.rb)\n* [RestrictToValidator](activemodel-validators/blob/master/lib/activemodel-validators/restrict_to_validator.rb)\n* [AtLeastOnePresentValidator](activemodel-validators/blob/master/lib/activemodel-validators/at_least_one_present_validator.rb)\n* [BlankValidator](activemodel-validators/blob/master/lib/activemodel-validators/blank_validator.rb)\n* [MultipleOfValidator](activemodel-validators/blob/master/lib/activemodel-validators/multiple_of_validator.rb)\n* [SumOfValidator](activemodel-validators/blob/master/lib/activemodel-validators/sum_of_validator.rb)\n\n* [DateValidator](activemodel-validators/blob/master/lib/activemodel-validators/date_validator.rb)\n* [YearValidator](activemodel-validators/blob/master/lib/activemodel-validators/year_validator.rb)\n\n* [PostalCodeValidator](activemodel-validators/blob/master/lib/activemodel-validators/postal_code_validator.rb)\n* [AddressStateValidator](activemodel-validators/blob/master/lib/activemodel-validators/address_state_validator.rb)\n\nInstallation\n============\n\nAdd to your Gemfile :\n\n```ruby\ngem 'activemodel-validators'\n```\n\n\nComparison to other validation gems/collections\n===============================================\n\nI like this idea from https://github.com/fnando/validators:\n\n```ruby\n    class Server \u003c ActiveRecord::Base\n      validates_datetime :starts_at\n      validates_datetime :ends_at, :after =\u003e :starts_at, :if =\u003e :starts_at?\n      validates_datetime :ends_at, :after =\u003e :now\n      validates_datetime :ends_at, :before =\u003e :today\n\n      validates :starts_at, :datetime =\u003e true\n    end\n```\n\nOther collections worth taking a look at:\n-----------------------------------------------\n\n* https://github.com/e-travel/evelpidon_validators\n    * Different\n    * Less\n    * More\n    * Associated\n    * Credit Card\n* https://github.com/cesario/activevalidators\n    * :postal_code =\u003e { :country =\u003e :us }\n    * :phone =\u003e true\n    * :password =\u003e { :strength =\u003e :medium }\n* https://github.com/fnando/validators\n* https://github.com/jeremiahishere/format_validators\n    * :phone_format =\u003e true\n    * Days of the Week\n\nOther collections not worth taking a look at:\n-----------------------------------------------\n\n* https://github.com/willian/rails_validators\n* https://github.com/infosimples/more_validators\n* https://github.com/aurels/extra_validators\n\nSpecialized validators that stand on their own:\n-----------------------------------------------\n\n* https://github.com/daddyz/phonelib (`phone: true`)\n* https://github.com/perfectline/validates_url\n* https://github.com/balexand/email_validator \n\n\nTo do\n=====\n\n* Write actual documentation\n* Add tests\n* Merge into/with an other existing gem\n\n\nLicense\n=======\n\nCopyright 2012, Tyler Rick\n\nThis is free software, distributed under the terms of the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftylerrick%2Factivemodel-validators","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftylerrick%2Factivemodel-validators","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftylerrick%2Factivemodel-validators/lists"}