{"id":13631831,"url":"https://github.com/thoughtbot/pacecar","last_synced_at":"2025-04-17T22:32:07.789Z","repository":{"id":438720,"uuid":"60528","full_name":"thoughtbot/pacecar","owner":"thoughtbot","description":"Generated scopes for ActiveRecord classes","archived":true,"fork":false,"pushed_at":"2016-07-01T15:19:26.000Z","size":436,"stargazers_count":435,"open_issues_count":0,"forks_count":22,"subscribers_count":42,"default_branch":"master","last_synced_at":"2024-11-06T09:19:04.668Z","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/thoughtbot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2008-10-07T18:56:13.000Z","updated_at":"2024-08-23T16:35:13.000Z","dependencies_parsed_at":"2022-07-08T07:44:39.560Z","dependency_job_id":null,"html_url":"https://github.com/thoughtbot/pacecar","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoughtbot%2Fpacecar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoughtbot%2Fpacecar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoughtbot%2Fpacecar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thoughtbot%2Fpacecar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thoughtbot","download_url":"https://codeload.github.com/thoughtbot/pacecar/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223768654,"owners_count":17199357,"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":[],"created_at":"2024-08-01T22:02:40.010Z","updated_at":"2024-11-08T23:31:42.345Z","avatar_url":"https://github.com/thoughtbot.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"Pacecar\n=======\n\n[![Build Status](https://secure.travis-ci.org/thoughtbot/pacecar.png?branch=master)](http://travis-ci.org/thoughtbot/pacecar)\n\nPacecar adds scope methods and other common functionality to ActiveRecord classes via database column introspection.\n\nPacecar automatically includes the Pacecar::Helpers module into all ActiveRecord::Base classes.\n\nTo get all Pacecar functionality, you need to \"include Pacecar\" in your class.\n\n    class User \u003c ActiveRecord::Base\n      include Pacecar\n    end\n\nTo get some subset (for example, only the state functionality), you can do something like \"include Pacecar::State\" to get only the module(s) you want.\n\n    class Post \u003c ActiveRecord::Base\n      include Pacecar::State\n    end\n\nPacecar supports mysql, postgres and sqlite database drivers, and is compatible with Rails 4.x versions.\n\nInstallation\n------------\n\nJust include in your Gemfile:\n\n    gem 'pacecar'\n\nUsage\n-----\n\nAssuming a database schema:\n\n    class CreateSchema \u003c ActiveRecord::Migration\n      def self.up\n        create_table :users, force: true do |t|\n          t.boolean :admin, default: false, null: false\n          t.datetime :approved_at\n          t.datetime :rejected_at\n          t.string :first_name\n          t.string :last_name\n          t.text :description\n          t.timestamps\n        end\n        create_table :posts, force: true do |t|\n          t.string :owner_type\n          t.integer :owner_id\n          t.string :publication_state\n          t.string :post_type\n          t.timestamps\n        end\n        create_table :comments, force: true do |t|\n          t.integer :user_id\n          t.text :description\n          t.integer :rating\n          t.timestamps\n        end\n      end\n    end\n\nAnd some basic model declarations:\n\n    class User \u003c ActiveRecord::Base\n      include Pacecar\n      has_many :posts, as: :owner\n      has_many :comments\n      has_many :articles\n    end\n\n    class Post \u003c ActiveRecord::Base\n      include Pacecar\n      PUBLICATION_STATES = %w(Draft Submitted Rejected Accepted)\n      TYPES = %w(Free Open Private Anonymous PostModern)\n      belongs_to :owner, polymorphic: true\n      has_state :publication_state\n      has_state :post_type, with: TYPES\n      has_polymorph :owner\n    end\n\n    class Comment \u003c ActiveRecord::Base\n      include Pacecar\n      belongs_to :user\n    end\n\n    class Article \u003c ActiveRecord::Base\n      belongs_to :user\n    end\n\nAll columns\n-----------\n\nRecords where approved\\_at is not null, or where it is null:\n\n    User.approved_at_present\n    User.approved_at_missing\n\nRecords where first\\_name is not null, or where it is null:\n\n    User.first_name_present\n    User.first_name_missing\n\nRecords ordered by first\\_name (default to 'asc', can specify to override):\n\n    User.by_first_name\n    User.by_first_name(:asc)\n    User.by_first_name(:desc)\n\nRecords where an attribute matches exactly a term:\n\n    User.first_name_equals('John')\n\nBoolean columns\n---------------\n\nRecords that are all admins or non-admins:\n\n    User.admin\n    User.not_admin\n\nPolymorphic relationships\n-------------------------\n\nRecords which have an owner\\_type of User:\n\n    Post.for_owner_type(User)\n\nState columns\n-------------\n\nRecords which are in a particular state, or not in a state:\n\n    Post.publication_state_draft\n    Post.post_type_not_open\n\nQuery methods on instances to check state:\n\n    Post.first.publication_state_draft?\n    Post.last.post_type_not_open?\n\nLimits\n------\n\nFirst x records:\n\n    User.limited(10)\n\nNamed scopes\n------------\n\nBecause these are all scope, you can combine them.\n\nTo get all users that have a first\\_name set, who are admins:\n\n    User.first_name_present.admin\n\nSupported Databases\n-------------------\n\n* MySQL\n* SQLite\n* Postgres\n\nCredits\n-------\n\n![thoughtbot](http://thoughtbot.com/images/tm/logo.png)\n\nPacecar is maintained and funded by [thoughtbot, inc](http://thoughtbot.com/community)\n\nThank you to all [the contributors](https://github.com/thoughtbot/pacecar/contributors)!\n\nThe names and logos for thoughtbot are trademarks of thoughtbot, inc.\n\nLicense\n-------\n\nPacecar is Copyright © 2008-2013 thoughtbot. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthoughtbot%2Fpacecar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthoughtbot%2Fpacecar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthoughtbot%2Fpacecar/lists"}