auto_seed 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 570a80405f90bdf4c8b3aa55314ef5ec3388507c29cd8aa353ab4e82beec1cfc
4
+ data.tar.gz: fcf0e87251ab915a047808aa55aa11780ff75c84f251d66e7825550556aedf83
5
+ SHA512:
6
+ metadata.gz: 9044caea2f2c2866202b65515de9db6bab7452bccb32a5f8710fcb516dd74f5d529523d2c50527ae7d5cf63848250f6f74a962d86face3350a569e4f2415dfca
7
+ data.tar.gz: 3217d78dc3e51e06cda25a317ca1690c0e186c8af8476a423e3971eb81b4612c0d74183ef710bbf8c56cc1a6af0adb36100a46256a9a5e642eced50683bf143f
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # AutoSeed
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/auto_seed`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/auto_seed. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/auto_seed/blob/main/CODE_OF_CONDUCT.md).
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
36
+
37
+ ## Code of Conduct
38
+
39
+ Everyone interacting in the AutoSeed project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/auto_seed/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+ require "standard/rake"
6
+
7
+ Dir.glob("lib/tasks/*.rake").each { |r| load r }
8
+
9
+ RSpec::Core::RakeTask.new(:spec)
10
+
11
+ task default: %i[spec standard]
data/db/seeds.rb ADDED
@@ -0,0 +1 @@
1
+ # Generated Seed Data
@@ -0,0 +1,47 @@
1
+ module AutoSeed
2
+ class Seeder
3
+ def self.generate_seed_file
4
+ File.open('db/seeds.rb', 'w') do |file|
5
+ ActiveRecord::Base.descendants.each do |model|
6
+ next if model.name.in?(%w[ApplicationRecord ActiveRecord::Base]) # Skip base classes
7
+
8
+ file.puts "## #{model.name} seeds"
9
+
10
+ begin
11
+ attributes = model.columns.reject { |col| col.name.in?(%w[ip_address current_sign_in_at]) }
12
+ file.puts "#{model.name}.create!("
13
+
14
+ attributes.each do |attribute|
15
+ file.puts " #{attribute.name}: 'sample_value',"
16
+ end
17
+
18
+ model.reflect_on_all_associations.each do |assoc|
19
+ case assoc.macro
20
+ when :has_many
21
+ file.puts " #{assoc.name}: [#{assoc.klass}.create!(...)]"
22
+ when :belongs_to
23
+ file.puts " #{assoc.name}: #{assoc.klass}.first"
24
+ when :has_one
25
+ file.puts " #{assoc.name}: #{assoc.klass}.create!(...)"
26
+ when :has_many_attached
27
+ file.puts " #{assoc.name}: [#{assoc.klass}.attach(...)]"
28
+ end
29
+
30
+ # Handle polymorphic associations
31
+ if assoc.polymorphic?
32
+ file.puts " #{assoc.name}_type: '#{assoc.klass}',"
33
+ file.puts " #{assoc.name}_id: #{assoc.klass}.first.id"
34
+ end
35
+ end
36
+
37
+ file.puts ");"
38
+ rescue StandardError => e
39
+ file.puts "# Error generating seed for #{model.name}: #{e.message}"
40
+ end
41
+
42
+ file.puts "\n"
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AutoSeed
4
+ VERSION = "0.1.0"
5
+ end
data/lib/auto_seed.rb ADDED
@@ -0,0 +1,12 @@
1
+ require_relative "auto_seed/version"
2
+ require_relative "auto_seed/seeder"
3
+
4
+
5
+ # lib/auto_seed.rb
6
+ module AutoSeed
7
+ class Error < StandardError; end
8
+
9
+ if defined?(Rake)
10
+ Dir[File.join(__dir__, 'tasks', '**', '*.rake')].each { |f| load f }
11
+ end
12
+ end
@@ -0,0 +1,6 @@
1
+ namespace :db do
2
+ desc "Generate seed file from schema comments"
3
+ task generate_seeds: :environment do
4
+ AutoSeed::Seeder.generate_seed_file
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: auto_seed
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Shobhit Shukla
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-07-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sqlite3
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '13.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
55
+ description: AutoSeed uses model schema comments to automatically generate seed files
56
+ for Rails applications.
57
+ email:
58
+ - shobits001@outlook.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - README.md
64
+ - Rakefile
65
+ - db/seeds.rb
66
+ - lib/auto_seed.rb
67
+ - lib/auto_seed/seeder.rb
68
+ - lib/auto_seed/version.rb
69
+ - lib/tasks/auto_seed.rake
70
+ homepage: https://github.com/shobhit-shukla/auto_seed
71
+ licenses:
72
+ - MIT
73
+ metadata:
74
+ allowed_push_host: https://rubygems.org
75
+ homepage_uri: https://github.com/shobhit-shukla/auto_seed
76
+ source_code_uri: https://github.com/shobhit-shukla/auto_seed
77
+ changelog_uri: https://github.com/shobhit-shukla/auto_seed
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: 3.0.0
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubygems_version: 3.5.11
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: A gem to generate seed files from model schema comments
97
+ test_files: []