{"id":13427723,"url":"https://github.com/kaize/validates","last_synced_at":"2025-03-16T00:32:07.857Z","repository":{"id":1863980,"uuid":"2789106","full_name":"kaize/validates","owner":"kaize","description":null,"archived":false,"fork":false,"pushed_at":"2017-01-13T11:02:51.000Z","size":68,"stargazers_count":155,"open_issues_count":2,"forks_count":27,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-02-28T21:37:51.752Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kaize.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-11-16T16:19:04.000Z","updated_at":"2025-02-27T05:12:31.000Z","dependencies_parsed_at":"2022-09-14T04:30:41.860Z","dependency_job_id":null,"html_url":"https://github.com/kaize/validates","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaize%2Fvalidates","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaize%2Fvalidates/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaize%2Fvalidates/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaize%2Fvalidates/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kaize","download_url":"https://codeload.github.com/kaize/validates/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243809865,"owners_count":20351403,"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-07-31T01:00:39.302Z","updated_at":"2025-03-16T00:32:07.478Z","avatar_url":"https://github.com/kaize.png","language":"Ruby","readme":"# Validates [![Gem Version](https://badge.fury.io/rb/validates.png)](http://badge.fury.io/rb/validates) [![Build Status](https://travis-ci.org/kaize/validates.png)](https://travis-ci.org/kaize/validates) [![Code Climate](https://codeclimate.com/github/kaize/validates.png)](https://codeclimate.com/github/kaize/validates)\n\nCollection of useful custom validators for Rails applications, including:\n\n- AbsolutePathValidator\n- AssociationLengthValidator\n- ColorValidator\n- EanValidator ([EAN-8 \u0026 EAN-13](http://en.wikipedia.org/wiki/International_Article_Number_(EAN)))\n- EmailValidator\n- IpValidator\n- MoneyValidator\n- SlugValidator\n- UriComponentValidator\n- UrlValidator\n\n**Note** InnValidator and other Russian specific validators could be found at [validates_russian](https://github.com/asiniy/validates_russian) gem\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n``` ruby\ngem 'validates'\n```\n\nOr install it yourself as:\n\n``` bash\n$ gem install 'validates'\n```\n\n## Usage\n\nFor most of the validators you just want to add this line to your model:\n``` ruby\nvalidates :attribute, \u003cvalidator_underscore\u003e: true\n```\nwhere `\u003cvalidator_underscore\u003e` is an underscored, lowercase form from the validator's name (see the examples section below).\n\n### AssociationLengthValidator\n\nBecause this is the successor of ActiveModel::Validations::LengthValidator\nvalidator, it inherits all the options of the latter, such as `:is`, `:minimum`,\n`:maximum`, etc. Another option, which you may be interested in is `:select` option,\nwhich allows you to filter the collection of the associated objects.\n\n## Examples\n\n``` ruby\nclass User \u003c ActiveRecord::Base\n  validates :email, :email =\u003e true\n  validates :site, :url =\u003e true, :allow_blank =\u003e true\nend\n\nclass Company \u003c ActiveRecord::Base\n  # note AssociationLengthValidator is inherited from ActiveModel::Validations::LengthValidator\n  # http://api.rubyonrails.org/classes/ActiveModel/Validations/LengthValidator.html\n  # so you can easily use standard options like :is, :minimum, :maximum, etc.\n\n  validates :employees,\n  :association_length =\u003e {\n    :minimum =\u003e 1,\n    :select =\u003e -\u003e(employee) { employee.name.in? [\"Mike\", \"John\"] }\n  }\n\n  validates :employees, :association_length =\u003e { :minimum =\u003e 1, :select =\u003e :employees_filter }\n\n  def employees_filter(employees)\n    employees.select { |employee| employee.name.in? [\"Mike\", \"John\"] }\n  end\nend\n\nclass Page \u003c ActiveRecord::Base\n  validates :slug, :slug =\u003e true\nend\n\nclass Content \u003c ActiveRecord::Base\n  # Validates URI component.\n  # URI component must be of the following type:\n  # :ABS_URI, :REL_URI, :URI_REF, :ABS_URI_REF, :REL_URI_REF, :ESCAPED, :UNSAFE, :SCHEME,\n  # :USERINFO, :HOST, :PORT, :OPAQUE, :REGISTRY, :ABS_PATH, :REL_PATH, :QUERY or :FRAGMENT.\n  # These types are provided URI library. For more info see URI::DEFAULT_PARSER.regexp.\n\n  validates :path, :uri_component =\u003e { :component =\u003e :ABS_PATH }\nend\n\n```\n\n## Contributing\n\nPlease see [CONTRIBUTING.md](CONTRIBUTING.md) for details.\n\n## Credits\n\nOriginally written by Mikhail Stolbov. Maintained by kaize.\n\nThank you to all our amazing [contributors](http://github.com/kaize/validates/contributors)!\n\n## License\n\nvalidates is Copyright © 2012-2014 Mikhail Stolbov and kaize. It is free\nsoftware, and may be redistributed under the terms specified in the LICENSE\nfile.\n","funding_links":[],"categories":["Active Record","Ruby","模型"],"sub_categories":["Omniauth"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaize%2Fvalidates","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkaize%2Fvalidates","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaize%2Fvalidates/lists"}