{"id":15512752,"url":"https://github.com/westonganger/rearmed_rails","last_synced_at":"2025-10-12T09:31:44.621Z","repository":{"id":56891317,"uuid":"83454162","full_name":"westonganger/rearmed_rails","owner":"westonganger","description":"A collection of helpful methods and monkey patches for Rails","archived":true,"fork":false,"pushed_at":"2023-05-18T17:21:35.000Z","size":44,"stargazers_count":33,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-08T04:16:59.584Z","etag":null,"topics":["monkey-patching","rails","ruby","utility"],"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/westonganger.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-28T16:23:19.000Z","updated_at":"2023-10-17T00:44:30.000Z","dependencies_parsed_at":"2025-01-29T14:42:50.584Z","dependency_job_id":null,"html_url":"https://github.com/westonganger/rearmed_rails","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/westonganger/rearmed_rails","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/westonganger%2Frearmed_rails","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/westonganger%2Frearmed_rails/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/westonganger%2Frearmed_rails/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/westonganger%2Frearmed_rails/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/westonganger","download_url":"https://codeload.github.com/westonganger/rearmed_rails/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/westonganger%2Frearmed_rails/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279009181,"owners_count":26084555,"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-11T02:00:06.511Z","response_time":55,"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":["monkey-patching","rails","ruby","utility"],"created_at":"2024-10-02T09:53:50.077Z","updated_at":"2025-10-12T09:31:44.263Z","avatar_url":"https://github.com/westonganger.png","language":"Ruby","funding_links":["https://ko-fi.com/A5071NK'"],"categories":["Ruby"],"sub_categories":[],"readme":"# Rearmed Rails\n\n\u003ca href=\"https://badge.fury.io/rb/rearmed_rails\" target=\"_blank\"\u003e\u003cimg height=\"21\" style='border:0px;height:21px;' border='0' src=\"https://badge.fury.io/rb/rearmed_rails.svg\" alt=\"Gem Version\"\u003e\u003c/a\u003e\n\u003ca href='https://github.com/westonganger/rearmed_rails/actions' target='_blank'\u003e\u003cimg src=\"https://github.com/westonganger/rearmed_rails/workflows/Tests/badge.svg\" style=\"max-width:100%;\" height='21' style='border:0px;height:21px;' border='0' alt=\"CI Status\"\u003e\u003c/a\u003e\n\u003ca href='https://rubygems.org/gems/rearmed_rails' target='_blank'\u003e\u003cimg height='21' style='border:0px;height:21px;' src='https://img.shields.io/gem/dt/rearmed_rails?color=brightgreen\u0026label=Rubygems%20Downloads' border='0' alt='RubyGems Downloads' /\u003e\u003c/a\u003e\n\u003ca href='https://ko-fi.com/A5071NK' target='_blank'\u003e\u003cimg height='22' style='border:0px;height:22px;' src='https://az743702.vo.msecnd.net/cdn/kofi1.png?v=a' border='0' alt='Buy Me a Coffee' /\u003e\u003c/a\u003e \n\n\nA collection of helpful methods and monkey patches for Rails\n\nThe difference between this library and others is that all monkey patching is performed in an opt-in way because you shouldnt be using methods that you dont know about.\n\n```ruby\n# Gemfile\n\ngem 'rearmed_rails'\n```\n\nRun `rails g rearmed_rails:setup` to create a settings files in `config/initializers/rearmed_rails.rb` where you can opt-in to the monkey patches available in the library. Set these values to true if you want to enable the applicable monkey patch.\n\n```ruby\n# config/initializers/rearmed.rb\n\nRearmedRails.enabled_patches = {\n  active_record: {\n    find_duplicates: false,\n    find_or_create: false,\n    newest: false,\n    pluck_to_hash: false,\n    pluck_to_struct: false,\n    reset_auto_increment: false,\n    reset_table: false\n  },\n  helpers: {\n    field_is_array: false,\n    link_to_confirm: false,\n    options_for_select_include_blank: false,\n    options_from_collection_for_select_include_blank: false\n  }\n}\n\nRearmedRails.apply_patches!\n```\n\nSome other argument formats the `enabled_patches` option accepts are:\n\n```ruby\n### Enable everything\nRearmedRails.enabled_patches = :all\n\n### Disable everything\nRearmedRails.enabled_patches = nil\n\n### Hash values can be boolean/nil values also\nRearmedRails.enabled_patches = {\n  active_record: true,\n  helpers: false,\n}\n```\n\nBy design, once `apply_patches!` is called then `RearmedRails.enabled_patches` is no longer editable and `apply_patches!` cannot be called again. If you try to do so, it will raise a `PatchesAlreadyAppliedError`. There is no-built in way of changing the patches, if you need to do so (which you shouldn't) that is up to you to figure out.\n\n\n## Rails\n\n### ActiveRecord\n\n```ruby\nPost.find_or_create(name: 'foo', content: 'bar') # use this instead of the super confusing first_or_create method\nPost.find_or_create!(name: 'foo', content: 'bar')\n\nPost.newest # get the newest post, by default ordered by :created_at\nPost.newest(:updated_at) # different sort order\nPost.newest(:published_at, :created_at) # multiple columns to sort on\n\nPost.pluck_to_hash(:name, :category, :id)\nPost.pluck_to_struct(:name, :category, :id)\n\nPost.reset_table # delete all records from table and reset autoincrement column (id), works with mysql/mariadb/postgresql/sqlite\n# or with options\nPost.reset_table(delete_method: :destroy) # to ensure all callbacks are fired\n\nPost.reset_auto_increment # reset mysql/mariadb/postgresql/sqlite auto-increment column, if contains records then defaults to starting from next available number\n# or with options\nPost.reset_auto_increment(value: 1, column: :id) # column option is only relevant for postgresql\n\nPost.find_duplicates # return active record relation of all records that have duplicates. By default it skips the primary_key, created_at, updated_at, \u0026 deleted_at columns\nPost.find_duplicates(:name) # find duplicates based on the name attribute\nPost.find_duplicates(:name, :category) # find duplicates based on the name \u0026 category attribute\nPost.find_duplicates(self.column_names.reject{|x| ['id','created_at','updated_at','deleted_at'].include?(x)})\n\n# It also can delete duplicates. \n# Valid values for keep are :first \u0026 :last.\n# Valid values for delete_method are :destroy \u0026 :delete. The soft-delete option is only used if you are using acts_as_paranoid on your model.\nPost.find_duplicates(:name, :category, delete: true)\nPost.find_duplicates(:name, :category, delete: {keep: :first, delete_method: :destroy, soft_delete: true}) # these are the default settings for delete: true\n```\n\n### Helpers\n\n```ruby\n# field_is_array: works with field type tag, form_for, simple form, etc\n= text_field_tag :name, is_array: true #=\u003e \u003cinput type='text' name='name[]' /\u003e\n\n# options_for_select_include_blank\noptions_for_select(@users.map{|x| [x.name, x.id]}, include_blank: true, selected: params[:user_id])\n\n# options_from_collection_for_select_include_blank\noptions_from_collection_for_select(@users, 'id', 'name', include_blank: true, selected: params[:user_id])\n\n# returns Rails v3 behaviour of allowing confirm attribute as well as data-confirm\n= link_to 'Delete', post_path(post), method: :delete, confirm: \"Are you sure you want to delete this post?\" \n```\n\n# Contributing\nIf you want to request a new method please raise an issue and we will discuss the idea. \n\n\n# Credits\nCreated by [Weston Ganger](https://westonganger.com) - [@westonganger](https://github.com/westonganger)\n\n## Other Libraries in the Rearmed family of Plugins\n- [Rearmed Ruby](https://github.com/westonganger/rearmed-rb)\n- [Rearmed JS](https://github.com/westonganger/rearmed_rails)\n- [Rearmed CSS](https://github.com/westonganger/rearmed_css)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwestonganger%2Frearmed_rails","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwestonganger%2Frearmed_rails","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwestonganger%2Frearmed_rails/lists"}