{"id":14969797,"url":"https://github.com/dandlezzz/active_conformity","last_synced_at":"2025-10-26T09:30:59.535Z","repository":{"id":35541871,"uuid":"39813174","full_name":"dandlezzz/active_conformity","owner":"dandlezzz","description":"Database driven validations","archived":false,"fork":false,"pushed_at":"2016-08-11T20:11:46.000Z","size":1915,"stargazers_count":12,"open_issues_count":0,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-31T18:03:33.930Z","etag":null,"topics":["activemodel","activerecord","rails","validation"],"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/dandlezzz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-28T04:32:56.000Z","updated_at":"2023-04-20T19:31:44.000Z","dependencies_parsed_at":"2022-09-13T11:00:35.583Z","dependency_job_id":null,"html_url":"https://github.com/dandlezzz/active_conformity","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dandlezzz%2Factive_conformity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dandlezzz%2Factive_conformity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dandlezzz%2Factive_conformity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dandlezzz%2Factive_conformity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dandlezzz","download_url":"https://codeload.github.com/dandlezzz/active_conformity/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238301279,"owners_count":19449414,"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":["activemodel","activerecord","rails","validation"],"created_at":"2024-09-24T13:42:23.957Z","updated_at":"2025-10-26T09:30:59.183Z","avatar_url":"https://github.com/dandlezzz.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ActiveConformity\n\n[![Join the chat at https://gitter.im/dandlezzz/active_conformity](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/dandlezzz/active_conformity?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n[![Code Climate](https://codeclimate.com/github/dandlezzz/active_conformity/badges/gpa.svg)](https://codeclimate.com/github/dandlezzz/active_conformity)\n\nYour favorite rails validations driven not by code but by your data.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'active_conformity'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install active_conformity\n\n## Usage\n\nActiveConformity comes with a helpful install generator.\n\n\t$ rails g active_conformity:install\n\n This will generate a migration for you that creates the conformables table. The table responsible for storing all of the validation data. Additionally, it will create a module in your lib file where you can write custom validation methods.\n\n\n ActiveConformity is for use when validating if objects are of a specific composition.\n For example, lets say you have the following model structure:\n\n ```ruby\n class Car\n \tbelongs_to :engine\n \t#attrs :size\n end\n\n class Engine\n\n end\n ```\n\nIn this example you have a database full of different engines. Each car instance has an engine. If you want ensure that the diesel engine is on a car of a size 2000 you have a couple of options.\n\n```ruby\nclass Car\n  belongs_to :engine\n  validate :proper_engine\n\n    def proper_engine\n    \treturn true if size \u003e= 2000 \u0026\u0026 engine.name == \"diesel\"\n        errors.add(\"car is too small for diesel engine\")\n    end\nend\n\n```\n\nThis works but can become very complex if you have lots of engines and each with their own special requirements of the car. ActiveConformity provides a way to add these conditions to your database, as json, and then run the validations from the persisted json, that json is referred to as a conformity_set.\n\n```ruby\ndiesel_engine = Engine.find_by(name: \"diesel\")\ndiesel_engine.add_conformity_set!( {size: {:numericality =\u003e { :greater_than =\u003e 2000} } }, conformist_type: \"Car\")\n\ncar = Car.create!(size: 2000, engine: diesel_engine)\ncar.conforms? # true\ncar2 = Car.create!(size: 1000, engine: diesel_engine)\ncar2.conforms? # false\ncar2.conformity_errors # [{size: \"car is too small for diesel engine\"}]\n\n```\n\nThe add_conformity_set! method saves the json to your database any time  a car has a diesel engine, calling .conforms? will check the car's size to ensure it can accomodate the diesel engine.\n\n##\n\nPlease note, lack of conformity does not prevent persistence as it does with .valid? in Rails. It is suggested that you implement this in a callback on the model.\n\n##\n\nActiveConformity refers to the objects that tell other objects what do as conformables and the objects that are being told what to do as conformists. In the example above, the car is the conformist and the engine is the conformable.\n\nThere are several methods available to inspect what makes an object conform. In the previous example if you want to see all of the rules the car must conform to you can do the following.\n\n```ruby\ncar.aggregate_conformity_set # {:size=\u003e {:numericality =\u003e { :greater_than =\u003e 2000} } }\n```\n\n\nThis shows all of the validations that the model will have to run through when .conforms? is called.\n\n##\n\nIn order to debug conformity errors, ActiveConformity provides several methods to query the database in order to get a better understanding of why the object conforms or does not.\n\n```ruby\ncar.conformable_references #returns [diesel_engine]\n```\nThe conformable references returns a list of all the objects that the car gets a conformity set from. Additionally, for even more fine grained debugging you can call\n\n```ruby\ncar.conformity_sets_by_reference # {\"Engine id: 1\" =\u003e{:size=\u003e {:numericality =\u003e { :greater_than =\u003e 2000} } } }\n```\nThis returns a complex hash that shows the id of all of the objects mapped to their individual conformity_set.\n\n## Removing Conformity sets\n\nActiveConformity provides two ways to remove a misplaced conformity rule or set from a conformable. For example, if you had incorrectly added an extra conformity set to the diesel engine, you could remove it like so:\n\n```ruby\n# the bad rule\ndiesel_engine.add_conformity_set!( {size: {:numericality =\u003e { :greater_than =\u003e 999999} } }, conformist_type: \"Car\")\n# remove it this way\ndiesel_engine.remove_coformity_rule!(:size)\n\n```\nAdditionally, if you want to remove all of the conformity sets for a conformable, you can do the following:\n\n```ruby\ndiesel_engine.remove_rules\n```\n\n##\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo 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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\n1. Fork it ( https://github.com/[my-github-username]/active_conformity/fork )\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n\n## Help and Inspiration\nThanks to [Dan Barrett](https://github.com/thoughtpunch) who has provided guidance and inspiration for this project.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdandlezzz%2Factive_conformity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdandlezzz%2Factive_conformity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdandlezzz%2Factive_conformity/lists"}