{"id":18513343,"url":"https://github.com/jbox-web/auto_increment","last_synced_at":"2025-04-09T06:33:11.676Z","repository":{"id":146101127,"uuid":"172659727","full_name":"jbox-web/auto_increment","owner":"jbox-web","description":"Automaticaly increments a field in ActiveRecord, easy ;)","archived":false,"fork":false,"pushed_at":"2024-09-06T16:06:26.000Z","size":213,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-09-06T19:13:41.791Z","etag":null,"topics":["activerecord","autoincrement","rails","ruby"],"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/jbox-web.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":"2019-02-26T07:26:37.000Z","updated_at":"2024-09-06T16:06:30.000Z","dependencies_parsed_at":"2023-05-15T02:00:19.767Z","dependency_job_id":"18968027-991e-42bf-b642-c6151f1bdce4","html_url":"https://github.com/jbox-web/auto_increment","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbox-web%2Fauto_increment","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbox-web%2Fauto_increment/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbox-web%2Fauto_increment/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbox-web%2Fauto_increment/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jbox-web","download_url":"https://codeload.github.com/jbox-web/auto_increment/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223367276,"owners_count":17134069,"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","autoincrement","rails","ruby"],"created_at":"2024-11-06T15:37:45.391Z","updated_at":"2024-11-06T15:37:46.232Z","avatar_url":"https://github.com/jbox-web.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AutoIncrement\n\n[![GitHub license](https://img.shields.io/github/license/jbox-web/auto_increment.svg)](https://github.com/jbox-web/auto_increment/blob/master/LICENSE)\n[![GitHub release](https://img.shields.io/github/release/jbox-web/auto_increment.svg)](https://github.com/jbox-web/auto_increment/releases/latest)\n[![CI](https://github.com/jbox-web/auto_increment/workflows/CI/badge.svg)](https://github.com/jbox-web/auto_increment/actions)\n[![Code Climate](https://codeclimate.com/github/jbox-web/auto_increment/badges/gpa.svg)](https://codeclimate.com/github/jbox-web/auto_increment)\n[![Test Coverage](https://codeclimate.com/github/jbox-web/auto_increment/badges/coverage.svg)](https://codeclimate.com/github/jbox-web/auto_increment/coverage)\n\nAutoIncrement provides automatic incrementation for a integer or string fields in Rails.\n\n## Installation\n\nPut this in your `Gemfile` :\n\n```ruby\ngit_source(:github){ |repo_name| \"https://github.com/#{repo_name}.git\" }\n\ngem 'auto_increment', github: 'jbox-web/auto_increment', tag: '1.8.0'\n```\n\nthen run `bundle install`.\n\n\n## Usage\n\nTo work with a auto increment column you used to do something like this in your model:\n\n```ruby\n  before_create :set_code\n  def set_code\n    max_code = Operation.maximum(:code)\n    self.code = max_code.to_i + 1\n  end\n```\n\nLooks fine, but not when you need to do it over and over again. In fact auto_increment does it under the cover.\n\nAll you need to do is this:\n\n```ruby\nclass Project \u003c ApplicationRecord\n  auto_increment :code\nend\n```\n\nAnd your code field will be incremented :)\n\n\n## Customizing\n\nSo you have a different column or need a scope. auto_increment provides options. You can use it like this:\n\n```ruby\nclass Project \u003c ApplicationRecord\n  auto_increment :letter, scope: [:account_id, :job_id], model_scope: :in_account, initial: 'C', force: true, lock: false, before: :create\nend\n```\n\nFirst argument is the column that will be incremented. Can be integer or string.\n\n* **scope:** you can define columns that will be scoped and you can use as many as you want (default: nil)\n* **model_scope:** you can define model scopes that will be executed and you can use as many as you want (default: nil)\n* **initial:** initial value of column (default: 1)\n* **force:** you can set a value before create and auto_increment will not change that, but if you do want this, set force to true (default: false)\n* **lock:** you can set a lock on the max query. (default: false)\n* **before:** you can choose a different callback to be used (:create, :save, :validation) (default: create)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjbox-web%2Fauto_increment","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjbox-web%2Fauto_increment","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjbox-web%2Fauto_increment/lists"}