{"id":13394969,"url":"https://github.com/khiav223577/rails_or","last_synced_at":"2025-04-09T07:05:49.128Z","repository":{"id":15097713,"uuid":"77551168","full_name":"khiav223577/rails_or","owner":"khiav223577","description":"Cleaner syntax for writing OR Query in Rails 5, 6. And also add #or support to Rails 3 and 4.","archived":false,"fork":false,"pushed_at":"2024-09-14T18:12:15.000Z","size":157,"stargazers_count":94,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T05:59:57.830Z","etag":null,"topics":["activerecord","orm-extension","rails","rubygems","syntax-sugar"],"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/khiav223577.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2016-12-28T17:54:43.000Z","updated_at":"2024-09-14T18:12:18.000Z","dependencies_parsed_at":"2024-09-15T03:52:59.562Z","dependency_job_id":null,"html_url":"https://github.com/khiav223577/rails_or","commit_stats":{"total_commits":196,"total_committers":3,"mean_commits":65.33333333333333,"dds":"0.015306122448979553","last_synced_commit":"6a755d87a66bd217cf7de49f98b8dfb145f1b74d"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khiav223577%2Frails_or","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khiav223577%2Frails_or/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khiav223577%2Frails_or/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khiav223577%2Frails_or/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/khiav223577","download_url":"https://codeload.github.com/khiav223577/rails_or/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247994119,"owners_count":21030050,"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","orm-extension","rails","rubygems","syntax-sugar"],"created_at":"2024-07-30T17:01:37.764Z","updated_at":"2025-04-09T07:05:49.109Z","avatar_url":"https://github.com/khiav223577.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# RailsOr\n\n[![Gem Version](https://img.shields.io/gem/v/rails_or.svg?style=flat)](https://rubygems.org/gems/rails_or)\n[![Build Status](https://github.com/khiav223577/rails_or/workflows/Ruby/badge.svg)](https://github.com/khiav223577/rails_or/actions)\n[![RubyGems](http://img.shields.io/gem/dt/rails_or.svg?style=flat)](https://rubygems.org/gems/rails_or)\n[![Code Climate](https://codeclimate.com/github/khiav223577/rails_or/badges/gpa.svg)](https://codeclimate.com/github/khiav223577/rails_or)\n[![Test Coverage](https://codeclimate.com/github/khiav223577/rails_or/badges/coverage.svg)](https://codeclimate.com/github/khiav223577/rails_or/coverage)\n\n`rails_or` is a Ruby Gem for you to write cleaner `OR` query.\n\nIt will use built-in `or` method, which was added in Rails 5, when possible, so that you don't need to worry about that it will polulate `active_model`. Otherwise, it implements `or` method for Rails 3 and Rails 4.\n\n## Supports\n- Ruby 2.3 ~ 2.7, 3.0 ~ 3.2\n- Rails 3.2, 4.2, 5.0, 5.1, 5.2, 6.0, 6.1, 7.0, 7.2\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'rails_or'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install rails_or\n\n## Usage\n\n### Same as Rails 5's #or method\n```rb\nPerson.where(name: 'Pearl').or(Person.where(age: 24))\n\n# is the same as\nPerson.where(\"name = ? OR age = ?\", 'Pearl', 24)\n```\n\n### Clearer Syntax\n\n```rb\n# Before\nuser = User.where(account: account).or(User.where(email: account)).take\n\n# After\nuser = User.where(account: account).or(email: account).take\n```\n\n```rb\n# Before\nclass Post \u003c ActiveRecord::Base\n  scope :not_expired, -\u003e{ where(end_time: nil).or(Post.where('end_time \u003e ?', Time.now)) }\nend\n\n# After\nclass Post \u003c ActiveRecord::Base\n  scope :not_expired, -\u003e{ where(end_time: nil).or('end_time \u003e ?', Time.now) }\nend\n```\n\n\nNo need to repeat writing `Model.joins(XXX).where(...)`\n```rb\n# Before\nUser.joins(:posts).where(id: 2)\n                  .or(User.joins(:posts).where('posts.title = ?',\"title\"))\n                  .or(User.joins(:posts).where('posts.created_at \u003e ?', 1.day.ago))\n# After\nUser.joins(:posts).where(id: 2)\n                  .or('posts.title': \"title\")\n                  .or('posts.created_at \u003e ?', 1.day.ago)\n```\nSupport passing `Hash` / `Array` / `String` as parameters\n```rb\nPerson.where(name: 'Pearl').or(age: 24)\nPerson.where(name: 'Pearl').or(['age = ?', 24])\nPerson.where(name: 'Pearl').or('age = ?', 24)\nPerson.where(name: 'Pearl').or('age = 24')\n```\n\n## Other convenient methods\n\n### or_not\n(Only supports in Rails 4+)\n```rb\nCompany.where.not(logo_image1: nil)\n       .or_not(logo_image2: nil)\n       .or_not(logo_image3: nil)\n       .or_not(logo_image4: nil)\n```\n\n### or_having\n\n```rb\nOrder.group('user_id')\n     .having('SUM(price) \u003e 1000')\n     .or_having('COUNT(*) \u003e 10')\n```\n\n## Examples\n\nLet `A = { id: 1 }`, `B = { account: 'tester' }`, and `C = { email: 'test@example.com' }`\n\n### A \u0026\u0026 (B || C)\n```rb\nu = User.where(A)\nu.where(B).or(u.where(C))\n# =\u003e\n# SELECT `users`.* FROM `users`\n# WHERE `users`.`id` = 1 AND (`users`.`account` = 'tester' OR `users`.`email` = 'test@example.com')\n```\n### (B || C) \u0026\u0026 A\n```rb\nUser.where(B).or(C).where(A)\n# =\u003e\n# SELECT `users`.* FROM `users`\n# WHERE (`users`.`account` = 'tester' OR `users`.`email` = 'test@example.com') AND `users`.`id` = 1\n```\n### A \u0026\u0026 B || A \u0026\u0026 C\n```rb\nUser.where(A).where(B).or(User.where(A).where(C))\n# =\u003e\n# SELECT `users`.* FROM `users`\n# WHERE (`users`.`id` = 1 AND `users`.`account` = 'tester' OR `users`.`id` = 1 AND `users`.`email` = 'test@example.com')\n```\n### A \u0026\u0026 B || C\n```rb\nUser.where(A).where(B).or(C)\n# =\u003e\n# SELECT `users`.* FROM `users`\n# WHERE (`users`.`id` = 1 AND `users`.`account` = 'tester' OR `users`.`email` = 'test@example.com')\n```\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/khiav223577/rails_or. 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\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%2Fkhiav223577%2Frails_or","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkhiav223577%2Frails_or","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhiav223577%2Frails_or/lists"}