{"id":19684142,"url":"https://github.com/cedarcode/version_record","last_synced_at":"2025-11-11T20:01:16.636Z","repository":{"id":56897366,"uuid":"115656440","full_name":"cedarcode/version_record","owner":"cedarcode","description":"Semantic version management for database records using ActiveRecord","archived":false,"fork":false,"pushed_at":"2019-01-22T16:03:40.000Z","size":35,"stargazers_count":6,"open_issues_count":1,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-10-04T00:57:29.414Z","etag":null,"topics":["activerecord","rails","ruby","rubygems","version","versioning"],"latest_commit_sha":null,"homepage":"https://cedarcode.com","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/cedarcode.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2017-12-28T20:16:54.000Z","updated_at":"2025-03-24T16:19:39.000Z","dependencies_parsed_at":"2022-08-20T17:40:38.904Z","dependency_job_id":null,"html_url":"https://github.com/cedarcode/version_record","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cedarcode/version_record","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cedarcode%2Fversion_record","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cedarcode%2Fversion_record/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cedarcode%2Fversion_record/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cedarcode%2Fversion_record/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cedarcode","download_url":"https://codeload.github.com/cedarcode/version_record/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cedarcode%2Fversion_record/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278734983,"owners_count":26036515,"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","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["activerecord","rails","ruby","rubygems","version","versioning"],"created_at":"2024-11-11T18:16:56.212Z","updated_at":"2025-10-07T07:09:00.446Z","avatar_url":"https://github.com/cedarcode.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# version_record\n\n[![Build Status](https://travis-ci.org/cedarcode/version_record.svg?branch=master)](https://travis-ci.org/cedarcode/version_record)\n[![Code Climate](https://codeclimate.com/github/cedarcode/version_record/badges/gpa.svg)](https://codeclimate.com/github/cedarcode/version_record)\n[![Gem Version](https://badge.fury.io/rb/version_record.svg)](https://badge.fury.io/rb/version_record)\n\nversion_record provides a handful of tools to make versioning\n support super straight forward when it needs to be done at\n the database level. It makes use of ActiveRecord serialization\n and querying facilities to provide a nice API when dealing\n with versions. It relies heavily on [Semantic Versioning](https://semver.org/).\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'version_record'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install version_record\n\n## Usage\n\nThe more straight forward use case for this gem would be for\n an application implementing versioning at the database level. Let's\n say your application has a `documents` table for storing legal\n documents, which has a `version` column for storing the document\n version. Then you could do something like this:\n\n```ruby\nclass Document \u003c ActiveRecord::Base\n  versioned\nend\n```\n\nThis will generate the following behavior:\n\n```ruby\ndocument = Document.new(version: '2.0.0')\ndocument.version              # =\u003e #\u003cVersionRecord::Version:0x007fd171d5c8f8 @major=2, @minor=0, @patch=0, @prerelease=nil\u003e\n\ndocument.version.to_s         # =\u003e \"2.0.0\"\ndocument.version.bump         # =\u003e \"2.1.0\"\ndocument.version.bump(:major) # =\u003e \"3.0.0\"\ndocument.version.bump(:patch) # =\u003e \"3.0.1\"\ndocument.save!\n```\n\nIt will also generate two helper methods in your model called\n `by_version` and `latest_version`\n\n```ruby\nDocument.where(title: 'Terms of service').by_version(:desc) # =\u003e Will return a sorted list of \"Terms of service\" documents, ordered by version\nDocument.where(title: 'Terms of service').latest_version    # =\u003e Will return the latest \"Terms of service\" document\n```\n\n**WARNING**: `by_version` and `latest_version` are for now considered\n inefficient and you should be careful about using them with\n large sets of data. They use in-memory sorting, please use them\n at your own risk.\n\n### Storing versions\nVersions are treated seamlessly as normal attributes\n\n```ruby\nDocument.create!(version: '1.0.0')\n```\n\nOr you can use setters on objects:\n```ruby\ndocument.version = \"1.0.0.beta\"\ndocument.version.to_s # =\u003e \"1.0.0.beta\"\n```\n\n### Comparing versions\nVersion comparison work as you'd expect, honoring\n the [Semantic Versioning](https://semver.org/#semantic-versioning-specification-semver)\n specification:\n\n```ruby\ndocument_1 = Document.create!(version: '1.0.0')\ndocument_2 = Document.create!(version: '1.1.0')\ndocument_3 = Document.create!(version: '1.1.1.beta')\ndocument_4 = Document.create!(version: '1.1.1')\n\ndocument_1.version.class                # =\u003e VersionRecord::Version\ndocument_1.version \u003c document_2.version # =\u003e true\ndocument_2.version \u003c document_3.version # =\u003e true\ndocument_3.version \u003c document_4.version # =\u003e true\n```\n\n### Querying\nActiveRecord-style querying is supported. Versions are stored\nas strings in the end, so you can still use normal querying:\n\n```ruby\nDocument.where(version: '1.0.0')  # =\u003e Returns all the documents with version \"1.0.0\"\nDocument.find_by_version('2.0.0') # =\u003e Finds the document with version \"2.0.0\"\n```\n\nHowever, if you need to deal with version objects, this should\nalso work:\n\n```ruby\ndocument = Document.create!(version: '1.0.0') # =\u003e VersionRecord::Version\nDocument.where(version: document.version)     # =\u003e Returns all the documents with version \"1.0.0\"\nDocument.find_by_version(document.version)    # =\u003e Finds the document with version \"1.0.0\"\n```\n\n### String#to_version\nversion_record adds a handy helper for strings:\n```ruby\n\"1.0.0\".to_version     # =\u003e #\u003cVersionRecord::Version:0x007fd17191bca8...\n\"1.0.0-rc1\".to_version # =\u003e #\u003cVersionRecord::Version:0x007fd17191bca8...\n\"1...1\".to_version     # =\u003e ArgumentError: Malformed version number string 1...1\n```\n\n### Custom options\n\nIf your version column is not called `version` you can\n customize it with the `column_name` option. For example,\n let's say that the name of your column is `semantic_version`\n instead of `version`, then you can do:\n\n```ruby\nclass Document \u003c ActiveRecord::Base\n  versioned column_name: :semantic_version\nend\n```\n\nSo then calling `document.semantic_version` should properly\n respond with a version object:\n\n```ruby\ndocument.semantic_version # =\u003e #\u003cVersionRecord::Version:0x007fd171d5c8f8 @major=2, @minor=0, @patch=0, @prerelease=nil\u003e\n```\n\n## Contributing\n\n1. Fork it ( https://github.com/cedarcode/version_record/ )\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\nSee the [Running Tests](RUNNING_TESTS.md) guide for details on how to run the test suite.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcedarcode%2Fversion_record","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcedarcode%2Fversion_record","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcedarcode%2Fversion_record/lists"}