{"id":15403412,"url":"https://github.com/mbj/vanguard","last_synced_at":"2026-03-13T00:31:36.581Z","repository":{"id":7571392,"uuid":"8925779","full_name":"mbj/vanguard","owner":"mbj","description":"External validations for ruby objects","archived":false,"fork":false,"pushed_at":"2015-06-14T16:34:13.000Z","size":229,"stargazers_count":119,"open_issues_count":4,"forks_count":4,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-04-09T20:12:29.301Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mbj.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-03-21T09:54:44.000Z","updated_at":"2024-11-28T16:26:56.000Z","dependencies_parsed_at":"2022-09-06T21:52:50.769Z","dependency_job_id":null,"html_url":"https://github.com/mbj/vanguard","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbj%2Fvanguard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbj%2Fvanguard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbj%2Fvanguard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbj%2Fvanguard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mbj","download_url":"https://codeload.github.com/mbj/vanguard/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248103872,"owners_count":21048245,"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-10-01T16:08:26.106Z","updated_at":"2026-03-13T00:31:31.552Z","avatar_url":"https://github.com/mbj.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"vanguard\n========\n\nThis library provides external validations for any Ruby class.\n\nHistory:\n--------\n\nIt originates from [emmanuels aequitas repository](https://github.com/emmanuel/vanguard)\nwith the following changes:\n\n* Only support for external validators\n* Use composable algebra for internals\n* Will allow serialization to javascript for client side validation (not implemented)\n* No contextual validators anymore (use additional external validators)\n* 100% code rewrite\n* Use [equalizer](https://github.com/dkubb/equalizer) and [adamantium](https://github.com/dkubb/adamantium) where possible.\n\n## Specifying Validations\n\n```ruby\nrequire 'vanguard'\n\nclass ProgrammingLanguage\n  attr_reader :name\n\n  def initialize(name)\n    @name = name\n  end\nend\n\nVALIDATOR = Vanguard::Validator.build do\n  validates_presence_of :name\nend\n\nruby = ProgrammingLanguage.new('ruby')\n\nresult = VALIDATOR.call(ruby)\nresult.valid? # =\u003e true\nresult.violations # =\u003e #\u003cSet: {}\u003e\n\nother = ProgrammingLanguage.new('')\n\nresult = VALIDATOR.call(other)\nresult.valid? # =\u003e false\nresult.violations # =\u003e #\u003cSet: {\u003cVanguard:::Violation ....\u003e}\u003e\n```\n\nSee `Vanguard::Macros` to learn about the complete collection of validation rules available.\n\n## Credits\n\n* Markus Schirp [mbj](https://github.com/mbj)\n* Emmanuel Gomez [emmanuel](https://github.com/emmanuel)\n\n## Working with Validation Errors\n\nIf an instance fails one or more validation rules, `Vanguard::Violation` instances\nwill populate the `Vanguard::ViolationSet` object that is available through\nthe `Vanguard::Result#violations` method.\n\nVanguard currently has no support for generating human readable violation messages!\n\nFor example:\n\n```ruby\nresult = YOUR_VALIDATOR.call(Account.new(:name =\u003e \"Jose\"))\nif result.valid?\n  # my_account is valid and can be saved\nelse\n  result.violations.each do |e|\n    do_something_with(e)\n  end\nend\n```\n\n##Contextual Validation\n\nVanguard does not provide a means of grouping your validations into\ncontexts. Define a validator per context for this.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmbj%2Fvanguard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmbj%2Fvanguard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmbj%2Fvanguard/lists"}