{"id":19316749,"url":"https://github.com/maxim/transformable_list","last_synced_at":"2026-06-08T23:31:31.592Z","repository":{"id":56897092,"uuid":"77404175","full_name":"maxim/transformable_list","owner":"maxim","description":"Determine steps to transform a list into another list","archived":false,"fork":false,"pushed_at":"2016-12-26T22:57:28.000Z","size":8,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2026-05-01T14:15:33.939Z","etag":null,"topics":[],"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/maxim.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}},"created_at":"2016-12-26T19:58:22.000Z","updated_at":"2019-01-09T19:45:38.000Z","dependencies_parsed_at":"2022-08-20T17:40:29.302Z","dependency_job_id":null,"html_url":"https://github.com/maxim/transformable_list","commit_stats":null,"previous_names":["crossfield/transformable_list"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/maxim/transformable_list","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxim%2Ftransformable_list","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxim%2Ftransformable_list/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxim%2Ftransformable_list/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxim%2Ftransformable_list/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maxim","download_url":"https://codeload.github.com/maxim/transformable_list/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxim%2Ftransformable_list/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34085321,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-08T02:00:07.615Z","response_time":111,"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":"2024-11-10T01:12:35.268Z","updated_at":"2026-06-08T23:31:31.571Z","avatar_url":"https://github.com/maxim.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TransformableList\n\nNeed to transform one list into another without wreaking too much havoc? Just follow the steps.\n\n```\n\u003e\u003e TransformableList.new(%w(c a x b)).transform(%w(a b c d e))\n=\u003e [\n     [:delete, \"x\", 2],\n     [:create, \"d\", 3],\n     [:create, \"e\", 4],\n     [:move, \"a\", 0],\n     [:move, \"b\", 1],\n     [:move, \"c\", 2]\n   ]\n```\n\nEach step is `[action, item, index]` where action can be\n\n- delete\n- create\n- move\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'transformable_list'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install transformable_list\n\n## Matcher\n\nYou can change what items are considered equal by supplying a matcher.\n\n```ruby\nTransformableList.new(%(a foo), matcher: -\u003e a, b { a.size == b.size })\n```\n\nThe default is `-\u003e a, b { a == b }`.\n\n## Use case\n\nA use case for this gem could be an ActiveRecord has_many association that maintains a sequential index field. Let's say you have a voting system, and a user would assign all the choices by assigning an array. When you are updating existing choices into new ones, you want to keep most of them intact. You can then use logic like this:\n\n```ruby\noriginal_list = TransformableList.new(choices, matcher: -\u003e a, b { a['text'] == b['text'] })\nsteps = original_list.transform(new_list)\n\nsteps.each do |step|\n  action, item, index = step\n\n  case action\n  when :delete then item.destroy\n  when :create then choices.create(text: item['text'], index: index)\n  when :move then item.update_attribute(:index, index)\n  end\nend\n```\n\n## Algorithm efficiency\n\nThe gem was not intended for big lists, and efficiency wasn't a concern. If you have ideas on how to make it more efficient, PRs are very welcome.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` 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## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/crossfield/transformable_list. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxim%2Ftransformable_list","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaxim%2Ftransformable_list","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxim%2Ftransformable_list/lists"}