{"id":19984656,"url":"https://github.com/twilightcoders/active_record-framing","last_synced_at":"2026-05-14T02:33:22.266Z","repository":{"id":74486279,"uuid":"185501953","full_name":"TwilightCoders/active_record-framing","owner":"TwilightCoders","description":null,"archived":false,"fork":false,"pushed_at":"2020-01-13T17:19:04.000Z","size":167,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-09T17:54:54.252Z","etag":null,"topics":["activerecord","cte","extension","utility-library"],"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/TwilightCoders.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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":"2019-05-08T01:08:45.000Z","updated_at":"2020-01-23T21:11:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"31505b8b-1ff9-42cf-b944-595b93597848","html_url":"https://github.com/TwilightCoders/active_record-framing","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/TwilightCoders/active_record-framing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TwilightCoders%2Factive_record-framing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TwilightCoders%2Factive_record-framing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TwilightCoders%2Factive_record-framing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TwilightCoders%2Factive_record-framing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TwilightCoders","download_url":"https://codeload.github.com/TwilightCoders/active_record-framing/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TwilightCoders%2Factive_record-framing/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286079811,"owners_count":27282121,"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-11-27T02:00:05.795Z","response_time":58,"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","cte","extension","utility-library"],"created_at":"2024-11-13T04:19:47.573Z","updated_at":"2025-11-27T03:03:27.764Z","avatar_url":"https://github.com/TwilightCoders.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![License     ](https://img.shields.io/github/license/TwilightCoders/active_record-framing.svg)]()\n[![Version     ](https://img.shields.io/gem/v/active_record-framing.svg)](https://rubygems.org/gems/active_record-framing)\n[![Build Status](https://travis-ci.org/TwilightCoders/active_record-framing.svg)](https://travis-ci.org/TwilightCoders/active_record-framing)\n[![Maintenence ](https://api.codeclimate.com/v1/badges/762cdcd63990efa768b0/maintainability)](https://codeclimate.com/github/TwilightCoders/active_record-framing/maintainability)\n[![Coverage    ](https://codeclimate.com/github/TwilightCoders/active_record-framing/badges/coverage.svg)](https://codeclimate.com/github/TwilightCoders/active_record-framing/coverage)\n\n# ActiveRecord::Framing\n\nWorks similar to `scopes`. Rather than modifying the where clause of the `ActiveRecord::Relation`, it creates a common table expression (CTE) to be applied upon execution.\n\nUnlike scopes, they do not affect the values of attributes upon creation.\n\n## Requirements\n\n- Ruby 2.3+\n- ActiveRecord 4.2+\n\n_Note: Check the builds to be sure your version is in-fact supported. The requirements are left unbounded on the upper constraint for posterity, but may not be gaurenteed to work._\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'active_record-framing'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install active_record-framing\n\n## Usage\n\nAny `ActiveRecord::Base` descendant has access to two additional methods: `frame` and `default_frame`.\n\n```ruby\nclass User \u003c ActiveRecord::Base\n  default_frame { where(active: true) }\n  # ...\nend\n```\nAfterwards, `User.all.to_sql` yields\n```sql\nWITH \"users\" AS\n  (SELECT \"users\".* FROM \"users\" WHERE \"users\".\"active\" = true)\nSELECT \"users\".* FROM \"users\"\n```\n\n```ruby\nclass Admin \u003c User\n  default_frame { where(arel_table[:kind].eq(1)) }\n  # ...\nend\n```\n\nNote: In `ActiveRecord` versions less than `5.2` (Arel `9.0`), `default_frames` where clauses must be constructed with `arel` (`arel_table[:column]` etc) for values other than `nil`, `true`, and `false`. This is due to a limitation with what ActiveRecord calls \"bind values\" (beyond the scope of this document).\n\nAfterwards, `Admin.all.to_sql` yields\n```sql\nWITH \"users\" AS\n  (SELECT \"users\".* FROM \"users\" WHERE \"users\".\"kind\" = 1)\n```\n\nSimilar to how `named_scopes` work in `ActiveRecord`, frames can be named:\n\n```ruby\nclass User \u003c ActiveRecord::Base\n  frame :admin, -\u003e { where(arel_table[:kind].eq(1)) }\n  # ...\nend\n```\n\nNamed frames are accessed through assigned consts under the original class. This helps avoid collision with scopes, and helps indicate the mutual exclusivity of frames (by design).\n\n```ruby\nUser::Admin.all.to_sql\n# =\u003e\n# WITH \"admin/users\" AS\n#   (SELECT \"users\".* FROM \"users\" WHERE \"users\".kind = 1)\n# SELECT \"admin/users\".* FROM \"admin/users\"\n```\n\n## Development\n\nAfter checking out the repo, run `bundle` to install dependencies. Then, run `bundle exec rspec` to run the tests.\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/TwilightCoders/active_record-framing. 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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwilightcoders%2Factive_record-framing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwilightcoders%2Factive_record-framing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwilightcoders%2Factive_record-framing/lists"}