{"id":28759907,"url":"https://github.com/codevise/snaps","last_synced_at":"2025-08-27T07:17:26.774Z","repository":{"id":29274653,"uuid":"32807362","full_name":"codevise/snaps","owner":"codevise","description":"Revisioning and tagging of ActiveRecord models.","archived":false,"fork":false,"pushed_at":"2015-04-09T15:19:57.000Z","size":290,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-07-28T15:56:51.760Z","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/codevise.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-24T15:27:18.000Z","updated_at":"2021-07-26T23:34:43.000Z","dependencies_parsed_at":"2022-08-29T20:51:13.200Z","dependency_job_id":null,"html_url":"https://github.com/codevise/snaps","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/codevise/snaps","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codevise%2Fsnaps","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codevise%2Fsnaps/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codevise%2Fsnaps/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codevise%2Fsnaps/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codevise","download_url":"https://codeload.github.com/codevise/snaps/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codevise%2Fsnaps/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272303369,"owners_count":24910371,"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-08-27T02:00:09.397Z","response_time":76,"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":[],"created_at":"2025-06-17T05:42:21.953Z","updated_at":"2025-08-27T07:17:26.769Z","avatar_url":"https://github.com/codevise.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Snaps\n\n[![Gem Version](https://badge.fury.io/rb/snaps.svg)](http://badge.fury.io/rb/snaps)\n[![Build Status](https://travis-ci.org/codevise/snaps.svg?branch=master)](https://travis-ci.org/codevise/snaps)\n[![Test Coverage](https://codeclimate.com/github/codevise/snaps/badges/coverage.svg)](https://codeclimate.com/github/codevise/snaps)\n[![Code Climate](https://codeclimate.com/github/codevise/snaps/badges/gpa.svg)](https://codeclimate.com/github/codevise/snaps)\n\nRevisioning and tagging of ActiveRecord models.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n    gem 'snaps'\n\nAnd then execute:\n\n    $ bundle\n\nRun the install generator:\n\n    $ rake snaps:install:migrations\n\nMigrate your database to create the `snaps_tags` table:\n\n    $ rake db:migrate\n\n## Basics\n\nSnaps maintains a table of \"named pointers\" called Tags to other models. Implemented as a polymorphic association. Revisions are kept in the original table and identified by a `perma_id` field.\n\nSnaps provides methods to create copies (snapshots) of models and tag these snapshots as needed.\n\n## Usage Examples\n\n### Basic Usage\n\nA model that is to be revisioned with snaps needs an integer field called `perma_id` and must include the mixin created by `Snaps.revision`.\n\n    # db/migrate/xxx_create_posts.rb\n    create_table :posts do |t|\n      t.integer(:perma_id)\n\n      t.string(:title)\n      t.text(:body)\n    end\n\n\n    # app/models/post.rb\n    class Post \u003c ActiveRecord::Base\n      include Snaps.revision\n    end\n\n\nNow you can create snapshots of your post instances.\n\n    post = Posts.create(body: 'Some text')\n    post_snapshot = post.snapshot!\n\n    post.perma_id == post_snapshot.perma_id # =\u003e true\n\nUsing Snaps Tags you can assign one revision to be a 'draft'.\n\n    post.perma_id # =\u003e 25\n    post.snaps_tag!(:draft)\n\n    draft = Post.with_snaps_tag(:draft).find_by_perma_id(25)\n\n### Using a default Tag\n\nIt's easy to create a workflow in which a new post will be tagged by default.\nAlso it's convenient to hide calls to `with_snaps_tag` in a scope on your domain models.\n\n\n    # app/models/post.rb\n    class Post \u003c ActiveRecord::Base\n      include Snaps.revision(default_tag: :draft)\n\n      scope :drafts, -\u003e { with_snaps_tag(:draft) }\n    end\n\n    # in controller\n    draft = Post.create(body: 'Some Text')\n\n    existing_draft = Post.drafts.find_by_perma_id(25)\n\n    draft.update(body: \"New text\")\n    draft.snapshot!\n\n### Managing Lifecycle of records with tags\n\n    # app/models/post.rb\n    class Post \u003c ActiveRecord::Base\n      include Snaps.revision(default_tag: :draft)\n\n      scope :drafts, -\u003e { with_snaps_tag(:draft) }\n      scope :published, -\u003e { with_snaps_tag(:published) }\n\n      def publish\n        snapshot!(tag: :published)\n      end\n    end\n\n    # in controller\n    draft = Post.drafts.find_by_perma_id(25)\n    draft.publish\n\n    all_published_posts = Post.published\n\n### Revisioning composite models\n\n\n    # db/migrate/xxx_create_sections.rb\n    create_table :sections do |t|\n      t.integer(:perma_id)\n      t.references(:post)\n\n      t.text(:body)\n    end\n\n    # app/models/section.rb\n    class Section \u003c ActiveRecord::Base\n      include Snaps.revision\n\n      belongs_to :post\n    end\n\n    # app/models/post.rb\n    class Post \u003c ActiveRecord::Base\n      include Snaps.revision(default_tag: :draft,\n                             components: [:sections])\n\n      has_many :sections\n\n      scope :drafts, -\u003e { with_snaps_tag(:draft) }\n      scope :published, -\u003e { with_snaps_tag(:published) }\n\n      def publish\n        snapshot!(tag: :published)\n      end\n    end\n\n    # in controller\n\n    draft = Post.drafts.find_by_perma_id(25)\n    draft.sections.create(body: \"Section text\")\n    post = draft.snapshot!\n\n    # snapshots of sections have been created\n\n    draft.sections.first.id != post.sections.first.id\n    draft.sections.first.body == post.sections.first.body\n\n\n### Accessing other revisions of a record\n\n    post.snaps_revisions.where('created_at \u003c ?', post.created_at)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodevise%2Fsnaps","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodevise%2Fsnaps","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodevise%2Fsnaps/lists"}