{"id":19575054,"url":"https://github.com/chief/acts_as_defaultable","last_synced_at":"2025-04-27T06:30:48.842Z","repository":{"id":2157360,"uuid":"3102817","full_name":"chief/acts_as_defaultable","owner":"chief","description":"A gem allowing an active_record model to be default(unique) based on a specified column","archived":false,"fork":false,"pushed_at":"2015-05-23T08:42:01.000Z","size":201,"stargazers_count":3,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-30T15:13:29.630Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chief.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-01-04T15:14:15.000Z","updated_at":"2015-05-23T08:26:43.000Z","dependencies_parsed_at":"2022-08-29T06:50:54.927Z","dependency_job_id":null,"html_url":"https://github.com/chief/acts_as_defaultable","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chief%2Facts_as_defaultable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chief%2Facts_as_defaultable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chief%2Facts_as_defaultable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chief%2Facts_as_defaultable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chief","download_url":"https://codeload.github.com/chief/acts_as_defaultable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224062762,"owners_count":17249289,"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-11-11T06:45:35.346Z","updated_at":"2024-11-11T06:45:36.162Z","avatar_url":"https://github.com/chief.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ActsAsDefaultable\n\n[![Build Status](https://travis-ci.org/chief/acts_as_defaultable.png?branch=master)](https://travis-ci.org/chief/acts_as_defaultable)\n[![Code Climate](https://codeclimate.com/github/chief/acts_as_defaultable.png)](https://codeclimate.com/github/chief/acts_as_defaultable)\n[![Gem Version](https://badge.fury.io/rb/acts_as_defaultable.png)](http://badge.fury.io/rb/acts_as_defaultable)\n[![Dependency Status](https://gemnasium.com/chief/acts_as_defaultable.png)](https://gemnasium.com/chief/acts_as_defaultable)\n\n## Description\n\nThis ``acts_as`` extension provides the capability for having a default object.\nThe class that has this specified needs to have a default column defined as an integer,\nstring or boolean on the mapped database table.\nThere is also optional support for each record to have a default object of another model.\n\n## Install\n\nIn your Gemfile\n\n```ruby\n  gem 'acts_as_defaultable'\n```\n\nCurrently is tested on rails3.2, ruby 1.9.3 and mysql\n\n## Example\n\n### Default object\n\n```ruby\n  class Country \u003c ActiveRecord::Base\n    acts_as_defaultable :default\n  end\n\n  gr = Country.new\n  gr.default = true\n  gr.save\n  Country.default == gr # =\u003e true\n  uk = Country.new\n  uk.default = true\n  uk.save\n  Country.default == gr # =\u003e false\n```\n\nIf no options provided `default` column is assumed.\n\n### Default object for each record\n\n```ruby\n  class User \u003c ActiveRecord::Base\n    acts_as_defaultable :default, relation: :post\n  end\n\n  class Post \u003c ActiveRecord::Base\n    after_destroy User.new\n  end\n\n  class Comment \u003c ActiveRecord::Base\n  end\n\n  user = User.new\n  post = Post.create\n  user.default_post = post\n  user.save\n  user.default_post == post # =\u003e true\n\n  post.destroy\n  user.reload\n  user.default_post == nil # =\u003e true\n\n  user.default_post = Comment.create\n  user.default_post == nil # =\u003e true\n```\n\nOnly an object of the relation class will be accepted.\nThe `after_destroy` callback is optional but will ensure that results stay consistent in the event\nthat a newly created **post** gets the same id as the one destroyed\n\n## Notes\n\nThe option to acts_as_defaultable is the `column` of the Model that defines default\nbehaviour. This column can be a string, a boolean or an integer with default\npositive values 'on', true, 1 and default negative values 'off', false, 0 respectively.\n\nThe column name for a default relation is `default_column` _ `relation_column` and can be either a string or an integer.\n\nExamples:\n\n```\n  class User \u003c ActiveRecord::Base\n    acts_as_defaultable :default, relation: :post\n  end\n```\n\nColumn name in users table must be `default_post`\n\n```\n  class User \u003c ActiveRecord::Base\n    acts_as_defaultable :unique, relation: :post\n  end\n```\n\nColumn name must be `unique_post`\n\n## License\n\nacts_as_defaultable is released under the [MIT License](http://opensource.org/licenses/MIT)\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchief%2Facts_as_defaultable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchief%2Facts_as_defaultable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchief%2Facts_as_defaultable/lists"}