{"id":13879684,"url":"https://github.com/clowne-rb/clowne","last_synced_at":"2025-05-14T18:04:02.640Z","repository":{"id":46313907,"uuid":"108140161","full_name":"clowne-rb/clowne","owner":"clowne-rb","description":"A flexible gem for cloning models","archived":false,"fork":false,"pushed_at":"2025-03-19T16:28:42.000Z","size":1197,"stargazers_count":318,"open_issues_count":8,"forks_count":20,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-13T12:45:20.593Z","etag":null,"topics":["activerecord","cloning","hacktoberfest","rails"],"latest_commit_sha":null,"homepage":"https://clowne.evilmartians.io","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/clowne-rb.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":"docs/supported_adapters.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-10-24T14:39:39.000Z","updated_at":"2025-03-27T04:00:05.000Z","dependencies_parsed_at":"2023-11-08T23:25:08.620Z","dependency_job_id":"6084605c-3063-4da8-9128-1b8bb80a2af3","html_url":"https://github.com/clowne-rb/clowne","commit_stats":{"total_commits":316,"total_committers":11,"mean_commits":"28.727272727272727","dds":0.2879746835443038,"last_synced_commit":"696a3bc30cf5c6e65e16fb66c23be7ee99aade5a"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clowne-rb%2Fclowne","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clowne-rb%2Fclowne/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clowne-rb%2Fclowne/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clowne-rb%2Fclowne/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clowne-rb","download_url":"https://codeload.github.com/clowne-rb/clowne/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254198452,"owners_count":22030964,"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":["activerecord","cloning","hacktoberfest","rails"],"created_at":"2024-08-06T08:02:28.891Z","updated_at":"2025-05-14T18:03:57.633Z","avatar_url":"https://github.com/clowne-rb.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"[![Gem Version](https://badge.fury.io/rb/clowne.svg)](https://badge.fury.io/rb/clowne)\n[![Build Status](https://github.com/clowne-rb/clowne/actions/workflows/rspec.yml/badge.svg?branch=master)](https://github.com/clowne-rb/clowne/actions?query=branch%3Amaster+)\n[![Docs](https://img.shields.io/badge/docs-link-brightgreen.svg)](https://clowne.evilmartians.io)\n\n# Clowne\n\nA flexible gem for cloning your models. Clowne focuses on ease of use and provides the ability to connect various ORM adapters.\n\n📖 Read [Evil Martians Chronicles](https://evilmartians.com/chronicles/clowne-clone-ruby-models-with-a-smile) to learn about possible use cases.\n\n📑 [Documentation](https://clowne.evilmartians.io)\n\n\u003ca href=\"https://evilmartians.com/\"\u003e\n\u003cimg src=\"https://evilmartians.com/badges/sponsored-by-evil-martians.svg\" alt=\"Sponsored by Evil Martians\" width=\"236\" height=\"54\"\u003e\u003c/a\u003e\n\n## Installation\n\nTo install Clowne with RubyGems:\n\n```ruby\ngem install clowne\n```\n\nOr add this line to your application's Gemfile:\n\n```ruby\ngem \"clowne\"\n```\n\n## Quick Start\n\nAssume that you have the following model:\n\n```ruby\nclass User \u003c ActiveRecord::Base\n  # create_table :users do |t|\n  #  t.string :login\n  #  t.string :email\n  #  t.timestamps null: false\n  # end\n\n  has_one :profile\n  has_many :posts\nend\n\nclass Profile \u003c ActiveRecord::Base\n  # create_table :profiles do |t|\n  #   t.string :name\n  # end\nend\n\nclass Post \u003c ActiveRecord::Base\n  # create_table :posts\nend\n```\n\nLet's declare our cloners first:\n\n```ruby\nclass UserCloner \u003c Clowne::Cloner\n  adapter :active_record\n\n  include_association :profile, clone_with: SpecialProfileCloner\n  include_association :posts\n\n  nullify :login\n\n  # params here is an arbitrary Hash passed into cloner\n  finalize do |_source, record, **params|\n    record.email = params[:email]\n  end\nend\n\nclass SpecialProfileCloner \u003c Clowne::Cloner\n  adapter :active_record\n\n  nullify :name\nend\n```\n\nNow you can use `UserCloner` to clone existing records:\n\n```ruby\nuser = User.last\n# =\u003e \u003c#User id: 1, login: 'clown', email: 'clown@circus.example.com'\u003e\n\noperation = UserCloner.call(user, email: \"fake@example.com\")\n# =\u003e \u003c#Clowne::Utils::Operation...\u003e\n\noperation.to_record\n# =\u003e \u003c#User id: nil, login: nil, email: 'fake@example.com'\u003e\n\noperation.persist!\n# =\u003e true\n\ncloned = operation.to_record\n# =\u003e \u003c#User id: 2, login: nil, email: 'fake@example.com'\u003e\n\ncloned.login\n# =\u003e nil\ncloned.email\n# =\u003e \"fake@example.com\"\n\n# associations:\ncloned.posts.count == user.posts.count\n# =\u003e true\ncloned.profile.name\n# =\u003e nil\n```\n\nTake a look at our [documentation](https://clowne.evilmartians.io) for more info!\n\n### Supported ORM adapters\n\nAdapter                                   |1:1         |*:1         | 1:M         | M:M                     |\n------------------------------------------|------------|------------|-------------|-------------------------|\n[Active Record](https://clowne.evilmartians.io/#/active_record)  | has_one    | belongs_to | has_many    | has_and_belongs_to|\n[Sequel](https://clowne.evilmartians.io/#/sequel)                | one_to_one | -          | one_to_many | many_to_many     |\n\n## Maintainers\n\n- [Vladimir Dementyev](https://github.com/palkan)\n\n- [Nikolay Sverchkov](https://github.com/ssnickolay)\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclowne-rb%2Fclowne","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclowne-rb%2Fclowne","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclowne-rb%2Fclowne/lists"}