{"id":13879622,"url":"https://github.com/ledermann/drafting","last_synced_at":"2025-07-25T10:35:52.256Z","repository":{"id":35851317,"uuid":"40135481","full_name":"ledermann/drafting","owner":"ledermann","description":"Ruby gem for saving drafts of ActiveRecord models","archived":false,"fork":false,"pushed_at":"2024-12-29T16:14:23.000Z","size":83,"stargazers_count":68,"open_issues_count":4,"forks_count":13,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-07-15T06:57:51.491Z","etag":null,"topics":["activerecord","rails","ruby","rubygems","saving-drafts"],"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/ledermann.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-08-03T16:27:43.000Z","updated_at":"2025-07-06T00:32:47.000Z","dependencies_parsed_at":"2024-01-13T20:57:33.931Z","dependency_job_id":"1c8f2d24-fde4-431b-8e92-856e2d40538e","html_url":"https://github.com/ledermann/drafting","commit_stats":{"total_commits":90,"total_committers":4,"mean_commits":22.5,"dds":0.05555555555555558,"last_synced_commit":"4e95f50a7cba68b7362f1e8fb4ecdd83aa33e4e0"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/ledermann/drafting","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ledermann%2Fdrafting","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ledermann%2Fdrafting/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ledermann%2Fdrafting/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ledermann%2Fdrafting/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ledermann","download_url":"https://codeload.github.com/ledermann/drafting/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ledermann%2Fdrafting/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266991121,"owners_count":24017738,"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-07-25T02:00:09.625Z","response_time":70,"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","saving-drafts"],"created_at":"2024-08-06T08:02:27.041Z","updated_at":"2025-07-25T10:35:52.193Z","avatar_url":"https://github.com/ledermann.png","language":"Ruby","readme":"# Drafting\n\nThis Ruby gem enhances `ActiveRecord::Base` to save a draft version of the current instance.\n\n[![Build Status](https://github.com/ledermann/drafting/actions/workflows/main.yml/badge.svg)](https://github.com/ledermann/drafting/actions)\n[![Code Climate](https://codeclimate.com/github/ledermann/drafting/badges/gpa.svg)](https://codeclimate.com/github/ledermann/drafting)\n[![Coverage Status](https://coveralls.io/repos/ledermann/drafting/badge.svg?branch=master)](https://coveralls.io/r/ledermann/drafting?branch=master)\n\n## Features\n\n* The gem stores all the data in **one** separate table and does not need to modify the existing tables\n* It handles drafts for different models\n* It allows saving draft for an instance which does not pass the validations\n* A draft stores associations and virtual attributes, too\n* A draft is optionally linked to a given user, so every user can manage his own drafts (invisible for the other users)\n* A draft is optionally linked to a parent instance. This helps showing existing drafts in a context (e.g. message drafts for a given topic)\n* Only 90 lines of code\n\n## Requirements\n\n- Ruby 3.0 or newer\n- ActiveRecord 6.1 or newer (including 7.1)\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'drafting'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install drafting\n\nFinally, generate and run the migration:\n\n    $ rails g drafting:migration\n    $ rake db:migrate\n\n\n## Usage\n\n### Simple example\n\n```ruby\nclass Message \u003c ActiveRecord::Base\n  has_drafts\nend\n\nmessage = Message.new content: \"Let's start with a simple example.\"\nmessage.save_draft(current_user)\n\n# Time passes ...\n\ndraft = Message.drafts(current_user).first\nmessage = draft.restore\nmessage.save!\n\ndrafts = Message.drafts(current_user)\nmessages = drafts.restore_all\n```\n\n### Migration\n\n#### 0.5.x\n\nStarting from 0.5.x, you will be able to save drafts under a non `User` model as such:\n```\nmessage.save_draft(author)\n```\n\nIf you are upgrading from previous versions, simply run `rails g drafting:migration` again to generate the mising migration files.\n\n### Linking to parent instance\n\n```ruby\nclass Topic \u003c ActiveRecord::Base\n  has_many :messages\nend\n\nclass Message \u003c ActiveRecord::Base\n  belongs_to :topic\n  has_drafts parent: :topic\nend\n\ntopic = Topic.create! title: 'World domination'\nmessage = topic.messages.build content: 'First step: Get some coffee.'\nmessage.save_draft(current_user)\n\n# Time passes ...\n\ndraft = topic.drafts(current_user).first\n# or\ndraft = Topic.child_drafts(current_user).first\n\nmessage = draft.restore\nmessage.save!\n```\n\n### Hints\n\n* `save_draft` is allowed only if the instance is not persisted yet\n* Doing `save_draft` overwrites a previous draft (if there is one)\n* After doing a `save`, the draft (if there is one) will be deleted\n* The `user` argument can be nil if you don't want to distinguish between multiple users\n* Saving draft stores the data via `Marshal.dump` and `Marshal.load`. If you don't like this or need some customization, you can override the instance methods `dump_to_draft` and `load_from_draft` (see source)\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also 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`, which will 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\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/ledermann/drafting. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](https://contributor-covenant.org) code of conduct.\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n\nBased on some code from the outdated gem [drafts](https://rubygems.org/gems/drafts). Used with kind permission of Alexey Kuznetsov (@lxkuz).\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fledermann%2Fdrafting","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fledermann%2Fdrafting","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fledermann%2Fdrafting/lists"}