{"id":15152722,"url":"https://github.com/blocknotes/auto-seeding","last_synced_at":"2025-09-29T23:32:10.146Z","repository":{"id":59150845,"uuid":"102196101","full_name":"blocknotes/auto-seeding","owner":"blocknotes","description":"Auto generate seeding data with ActiveRecord","archived":true,"fork":false,"pushed_at":"2017-09-30T20:22:51.000Z","size":18,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-15T00:17:25.296Z","etag":null,"topics":["activerecord","rails","rails5","ruby"],"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/blocknotes.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":"2017-09-02T12:48:43.000Z","updated_at":"2023-06-19T08:52:47.000Z","dependencies_parsed_at":"2022-09-14T04:03:58.580Z","dependency_job_id":null,"html_url":"https://github.com/blocknotes/auto-seeding","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blocknotes%2Fauto-seeding","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blocknotes%2Fauto-seeding/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blocknotes%2Fauto-seeding/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blocknotes%2Fauto-seeding/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/blocknotes","download_url":"https://codeload.github.com/blocknotes/auto-seeding/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234673608,"owners_count":18869698,"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","rails","rails5","ruby"],"created_at":"2024-09-26T16:21:51.854Z","updated_at":"2025-09-29T23:32:04.881Z","avatar_url":"https://github.com/blocknotes.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Auto-seeding [![Gem Version](https://badge.fury.io/rb/auto-seeding.svg)](https://badge.fury.io/rb/auto-seeding) [![Build Status](https://travis-ci.org/blocknotes/auto-seeding.svg)](https://travis-ci.org/blocknotes/auto-seeding)\n\nA component to auto generate seed data with ActiveRecord using a set of predefined or custom rules respecting models validations.\n\n## Install\n\n- Add to Gemfile: `gem 'auto-seeding'` (better in *development* group)\n- Edit the seed task:\n\n```rb\nauto_seeding = AutoSeeding::Seeder.new\n3.times.each do\n  auto_seeding.update( Author.new ).save!\nend\n```\n\n### Options\n\n- **conf/seeder**: seeding source [*nil* | *:faker* | *:ffaker*] (*:faker* requires Faker gem, *:ffaker* requires FFaker gem)\n- **conf/file**: load seed configuration from a local file\n- **auto_create**: array of nested associations to create while seeding (useful for has_one associations), ex. [*:profile*]\n- **ignore_attrs**: ignore some attributes, ex. [*:id*, *updated_at*]\n- **skip_associations**: array of nested associations to skip while seeding, ex. [*:posts*]\n- **sources**: configure sources rules for autoseed data\n\nConf file: see [data folder](https://github.com/blocknotes/auto-seeding/tree/master/lib/auto-seeding/data)\n\nGlobal options (shared between instances):\n\n```rb\nAutoSeeding::Seeder.config({\n  skip_associations: [:versions],\n  conf: {\n    seeder: :ffaker,\n  },\n})\n```\n\nInstance options:\n\n```rb\nautoseeding = AutoSeeding::Seeder.new({\n  auto_create: [:profile],       # array of symbols\n  conf: {\n    file: 'test/conf.yml',       # string\n    seeder: :faker,              # symbol - :faker or :ffaker\n  },\n  ignore_attrs: [:id],           # array of symbols - ignored attributes\n  skip_associations: [:author],  # array of symbols - ignored nested associations\n  sources: {                     # hash - keys: types, fields\n    types: {                     # hash - override basic types rules\n      integer: {\n        source_model: 'Random',\n        source_method: 'rand',\n        source_args: '0..100',\n      }\n    },\n    fields: [                    # array of hashes - override fields rules\n      {\n        in: ['name'],\n        source_model: 'Faker::StarWars',\n        source_method: 'character',\n        type: 'string'\n      },\n      {\n        regexp: '^(.+_|)title(|_.+)$',\n        source_model: 'Faker::Book',\n        source_method: 'title',\n        post_process: '-\u003e( val ) { val + \" (seeding)\" }',\n        type: 'string'\n      }\n    ]\n  }\n})\n```\n\n## Notes\n\nGenerated data can be manipulated easily before saving:\n\n```rb\nobj = auto_seeding.update( Author.new )\nobj.name = 'John Doe'\nobj.save!\n```\n\nField names can be changed using *append* and *prepend* options - example using Carrierwave remote url property:\n\n```rb\nAutoSeeding::Seeder.new({\n  sources: {\n    fields: [\n      {\n        regexp: '^(.+_|)photo(|_.+)$|^(.+_|)image(|_.+)$',\n        source_model: 'Faker::Avatar',\n        source_method: 'image',\n        prepend: 'remote_',\n        append: '_url',\n        type: 'string'\n      }\n    ]\n  }\n}\n```\n\nTo avoid problems with PaperTrail use:\n\n`AutoSeeding::Seeder.config({ skip_associations: [:versions] })`\n\n## Do you like it? Star it!\n\nIf you use this component just star it. A developer is more motivated to improve a project when there is some interest.\n\n## Contributors\n\n- [Mattia Roccoberton](http://blocknot.es) - creator, maintainer\n\n## License\n\n[MIT](LICENSE.txt)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblocknotes%2Fauto-seeding","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblocknotes%2Fauto-seeding","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblocknotes%2Fauto-seeding/lists"}