seed_builder 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 85c0a52e743506b14e76f91dbf1b0e8a524d6edb934df69490303200b37513ee
4
- data.tar.gz: 5a4f1a7083612b45fbc663c15b8ea48a1efbbaaef8a08149619a6fe4a804f499
3
+ metadata.gz: 1b046651ce167e13d68341cda56bf75e8be727243532be8f30eafabd0e17fe63
4
+ data.tar.gz: 715f90fc2df771d026da70e2714001c34f516dd04a354c1bc8a62e61df7a17b1
5
5
  SHA512:
6
- metadata.gz: 893889ebedc9e81076d5234ab0bb46eba553704055aaa96c8e63aab6d70753eaf53425b04cf0a00f55149d865829c84a7d4a50d102ff02ed9389f1f6440597dc
7
- data.tar.gz: e61fb9c54039470ce71bcdbdc9d460d30751b458cc44ce85eb4de359b4d020c19c05cc55ab90991e142c056d45a596a3f39d07297623fdb3f30fae992f9ba09c
6
+ metadata.gz: 3bc1a3b7455aa26097dae82b822cac3c6f6924bdb8bf8d83cf126932ab0042027dc14bb500f545bfe7a32c95abd5ada9b9e51ab600ec35b4a2e0d89798068ea4
7
+ data.tar.gz: f11835d4f4016c2217a0fcf468f436f68e97d031aaadfed043990f624aa64a428c60b27135c5a36968299754d10ccd64b064586ff74aaa7aee7eb2a60db4f272
@@ -11,5 +11,5 @@ jobs:
11
11
  checks: write
12
12
  contents: read
13
13
  steps:
14
- - uses: actions/checkout@v4
14
+ - uses: actions/checkout@v5
15
15
  - uses: trunk-io/trunk-action@v1
@@ -5,38 +5,94 @@ concurrency:
5
5
  group: ${{ github.workflow }}-${{ github.ref_name }}
6
6
  cancel-in-progress: false
7
7
  jobs:
8
- rspec:
8
+ test:
9
9
  runs-on: ubuntu-latest
10
10
  strategy:
11
11
  matrix:
12
- ruby: [ruby, jruby, truffleruby]
12
+ include:
13
+ - rails_version: rails-6.1
14
+ ruby_version: "3.1"
15
+ - rails_version: rails-7.2
16
+ ruby_version: "3.2"
17
+ - rails_version: rails-8.1
18
+ ruby_version: "3.3"
13
19
  steps:
14
- - uses: actions/checkout@v4
15
- - uses: ruby/setup-ruby@v1
20
+ - uses: actions/checkout@v5
21
+
22
+ - name: Set up Ruby
23
+ uses: ruby/setup-ruby@v1
16
24
  with:
17
- ruby-version: ${{ matrix.ruby }}
18
- bundler-cache: true
19
- - run: bundle exec rspec
20
- coverage:
21
- runs-on: ubuntu-latest
22
- steps:
23
- - uses: actions/checkout@v4
24
- - uses: ruby/setup-ruby@v1
25
+ ruby-version: ${{ matrix.ruby_version }}
26
+ bundler-cache: false
27
+
28
+ - name: Install appraisal gem
29
+ run: gem install appraisal --no-document
30
+
31
+ - name: Generate appraisal gemfile
32
+ run: |
33
+ # Convert rails-6.1 to rails_6.1 format for gemfile name
34
+ GEMFILE_NAME=$(echo "${{ matrix.rails_version }}" | tr '-' '_')
35
+ appraisal install ${{ matrix.rails_version }} || true
36
+ # Verify gemfile was created
37
+ if [ ! -f "gemfiles/${GEMFILE_NAME}.gemfile" ]; then
38
+ echo "Error: gemfile not created at gemfiles/${GEMFILE_NAME}.gemfile"
39
+ exit 1
40
+ fi
41
+ # Set BUNDLE_GEMFILE for subsequent steps
42
+ echo "BUNDLE_GEMFILE=gemfiles/${GEMFILE_NAME}.gemfile" >> $GITHUB_ENV
43
+
44
+ - name: Update lockfile for platform and Ruby version
45
+ run: |
46
+ GEMFILE_NAME=$(echo "${{ matrix.rails_version }}" | tr '-' '_')
47
+ GEMFILE_PATH="gemfiles/${GEMFILE_NAME}.gemfile"
48
+ export BUNDLE_GEMFILE=${GEMFILE_PATH}
49
+ if [ -f "${GEMFILE_PATH}.lock" ]; then
50
+ # Add Linux platform if needed
51
+ bundle lock --add-platform x86_64-linux --gemfile ${GEMFILE_PATH} 2>/dev/null || true
52
+ # Try to install - if it fails due to incompatible versions, regenerate lockfile
53
+ if ! bundle install --gemfile ${GEMFILE_PATH} 2>/dev/null; then
54
+ echo "Lockfile has incompatible versions, regenerating..."
55
+ rm -f "${GEMFILE_PATH}.lock"
56
+ bundle install --gemfile ${GEMFILE_PATH}
57
+ fi
58
+ fi
59
+
60
+ - name: Install dependencies
61
+ uses: ruby/setup-ruby@v1
25
62
  with:
63
+ ruby-version: ${{ matrix.ruby_version }}
26
64
  bundler-cache: true
27
- - run: bundle exec rspec
28
- - uses: codecov/codecov-action@v5
65
+
66
+ - name: Run tests
67
+ run: bundle exec appraisal ${{ matrix.rails_version }} rspec
68
+
69
+ - name: Upload coverage reports to Codecov
70
+ if: matrix.rails_version == 'rails-8.1'
71
+ uses: codecov/codecov-action@v5
29
72
  continue-on-error: true
30
73
  env:
31
74
  CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
32
- - uses: codecov/test-results-action@v1
33
- if: ${{ !cancelled() }}
75
+
76
+ - name: Upload test results to Codecov
77
+ if: matrix.rails_version == 'rails-8.1'
78
+ uses: codecov/test-results-action@v1
34
79
  continue-on-error: true
35
80
  with:
36
81
  token: ${{ secrets.CODECOV_TOKEN }}
37
82
  files: coverage/junit-coverage.xml
38
- - uses: codacy/codacy-coverage-reporter-action@v1.3.0
39
- continue-on-error: true
40
- with:
41
- project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
42
- coverage-reports: coverage/coverage.xml
83
+
84
+ - name: Run linter
85
+ if: matrix.rails_version == 'rails-8.1'
86
+ env:
87
+ BUNDLE_GEMFILE: Gemfile
88
+ run: |
89
+ bundle install
90
+ bundle exec standardrb --format simple
91
+
92
+ - name: Check type signatures
93
+ if: matrix.rails_version == 'rails-8.1'
94
+ env:
95
+ BUNDLE_GEMFILE: Gemfile
96
+ run: |
97
+ bundle install
98
+ bundle exec rbs validate
data/.gitignore CHANGED
@@ -22,3 +22,4 @@
22
22
 
23
23
  *.local
24
24
  *.gem
25
+ /gemfiles
data/.standard.yml ADDED
@@ -0,0 +1,22 @@
1
+ # Standard Ruby configuration
2
+ # See https://github.com/standardrb/standard for more options
3
+
4
+ # Ignore specific files/directories
5
+ ignore:
6
+ - "bin/**/*"
7
+ - "tmp/**/*"
8
+ - "vendor/**/*"
9
+ - "coverage/**/*"
10
+ - "*.gem"
11
+ - "*.gemspec"
12
+
13
+ # Exclude certain rules if needed
14
+ # For example, if you want to allow longer lines:
15
+ # rubocop:
16
+ # AllCops:
17
+ # MaxLineLength: 120
18
+ # Disable frozen_string_literal to allow removal of those comments
19
+ rubocop:
20
+ Style/FrozenStringLiteralComment:
21
+ Enabled: false
22
+
data/Appraisals ADDED
@@ -0,0 +1,15 @@
1
+ appraise "rails-6.1" do
2
+ gem "rails", "~> 6.1.0"
3
+ gem "activerecord", "~> 6.1.0"
4
+ gem "sqlite3", "~> 1.4"
5
+ end
6
+
7
+ appraise "rails-7.2" do
8
+ gem "rails", "~> 7.2.0"
9
+ gem "activerecord", "~> 7.2.0"
10
+ end
11
+
12
+ appraise "rails-8.1" do
13
+ gem "rails", "~> 8.1.0"
14
+ gem "activerecord", "~> 8.1.0"
15
+ end
data/CHANGELOG.md CHANGED
@@ -1,17 +1,38 @@
1
- # 1.2.0
1
+ # CHANGELOG
2
+
3
+ ## 1.3.0 (2025-11-04)
4
+
5
+ - Replace `puts` statements with `Rails.logger` for proper logging integration
6
+ - Add tagged logging with `seed` tag for all seed-related log messages
7
+ - Add `logger` configuration option to allow custom logger setup via `SeedBuilder.config.logger = custom_logger`
8
+ - Fix seed file loading to use `load` instead of `require` to ensure files are re-executed on each seed run
9
+ - Logger automatically detects if `Rails.logger` already supports tagging to avoid double-wrapping
10
+ - Add ability to run specific seed files on demand using `bin/rails seed:run[SEED_NAME]`
11
+ - Add `load_seed_file` method to `SeedBuilder::Loader` for loading individual seeds
12
+ - Add ambiguous match detection: when multiple seed files match the same name, the loader will show an error listing all matches and prompt the user to use the full name with timestamp
13
+ - Patch `Rails.application.load_seed` to use SeedBuilder loader via Railtie integration
14
+
15
+ ## 1.2.1
16
+
17
+ - Fix seed files to be loaded as `.rb` files
18
+ - Add `default_seeds_full_path` config option to control default seeds full path
19
+ - Fix files loading using absolute paths
20
+ - Improve test coverage
21
+
22
+ ## 1.2.0
2
23
 
3
24
  - Automatically configure loader for Rails seeds
4
25
  - Add `use_seed_loader` config option to control loader usage
5
26
 
6
- # 1.1.0
27
+ ## 1.1.0
7
28
 
8
29
  - Fix `seeds_path` to be relative to Rails root
9
30
  - Improve test coverage for generator
10
31
 
11
- # 1.0.1
32
+ ## 1.0.1
12
33
 
13
34
  - Fix boolean config options to properly handle `nil` and `false` values
14
35
 
15
- # 1.0.0
36
+ ## 1.0.0
16
37
 
17
38
  - Initial version
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- seed_builder (1.2.0)
5
- activerecord (>= 6, < 8.1)
6
- rails (>= 6, < 8.1)
4
+ seed_builder (1.3.0)
5
+ activerecord (>= 6.1, < 8.2)
6
+ rails (>= 6.1, < 8.2)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
@@ -79,6 +79,11 @@ GEM
79
79
  securerandom (>= 0.3)
80
80
  tzinfo (~> 2.0, >= 2.0.5)
81
81
  uri (>= 0.13.1)
82
+ appraisal (2.5.0)
83
+ bundler
84
+ rake
85
+ thor (>= 0.14.0)
86
+ ast (2.4.3)
82
87
  base64 (0.2.0)
83
88
  benchmark (0.4.0)
84
89
  bigdecimal (3.1.8)
@@ -103,6 +108,10 @@ GEM
103
108
  rdoc (>= 4.0.0)
104
109
  reline (>= 0.4.2)
105
110
  jar-dependencies (0.5.0)
111
+ json (2.15.2)
112
+ json (2.15.2-java)
113
+ language_server-protocol (3.17.0.5)
114
+ lint_roller (1.1.0)
106
115
  logger (1.6.2)
107
116
  loofah (2.23.1)
108
117
  crass (~> 1.0.2)
@@ -141,6 +150,11 @@ GEM
141
150
  racc (~> 1.4)
142
151
  nokogiri (1.16.8-x86_64-linux)
143
152
  racc (~> 1.4)
153
+ parallel (1.27.0)
154
+ parser (3.3.10.0)
155
+ ast (~> 2.4.1)
156
+ racc
157
+ prism (1.6.0)
144
158
  psych (5.2.1)
145
159
  date
146
160
  stringio
@@ -185,9 +199,13 @@ GEM
185
199
  rake (>= 12.2)
186
200
  thor (~> 1.0, >= 1.2.2)
187
201
  zeitwerk (~> 2.6)
202
+ rainbow (3.1.1)
188
203
  rake (13.2.1)
204
+ rbs (3.9.5)
205
+ logger
189
206
  rdoc (6.8.1)
190
207
  psych (>= 4.0.0)
208
+ regexp_parser (2.11.3)
191
209
  reline (0.5.12)
192
210
  io-console (~> 0.5)
193
211
  rexml (3.3.9)
@@ -206,6 +224,25 @@ GEM
206
224
  rspec-support (3.13.2)
207
225
  rspec_junit_formatter (0.6.0)
208
226
  rspec-core (>= 2, < 4, != 2.12.0)
227
+ rubocop (1.80.2)
228
+ json (~> 2.3)
229
+ language_server-protocol (~> 3.17.0.2)
230
+ lint_roller (~> 1.1.0)
231
+ parallel (~> 1.10)
232
+ parser (>= 3.3.0.2)
233
+ rainbow (>= 2.2.2, < 4.0)
234
+ regexp_parser (>= 2.9.3, < 3.0)
235
+ rubocop-ast (>= 1.46.0, < 2.0)
236
+ ruby-progressbar (~> 1.7)
237
+ unicode-display_width (>= 2.4.0, < 4.0)
238
+ rubocop-ast (1.47.1)
239
+ parser (>= 3.3.7.2)
240
+ prism (~> 1.4)
241
+ rubocop-performance (1.25.0)
242
+ lint_roller (~> 1.1)
243
+ rubocop (>= 1.75.0, < 2.0)
244
+ rubocop-ast (>= 1.38.0, < 2.0)
245
+ ruby-progressbar (1.13.0)
209
246
  securerandom (0.4.0)
210
247
  simplecov (0.22.0)
211
248
  docile (~> 1.1)
@@ -224,11 +261,26 @@ GEM
224
261
  sqlite3 (2.4.0-x86-linux-gnu)
225
262
  sqlite3 (2.4.0-x86_64-darwin)
226
263
  sqlite3 (2.4.0-x86_64-linux-gnu)
264
+ standard (1.51.1)
265
+ language_server-protocol (~> 3.17.0.2)
266
+ lint_roller (~> 1.0)
267
+ rubocop (~> 1.80.2)
268
+ standard-custom (~> 1.0.0)
269
+ standard-performance (~> 1.8)
270
+ standard-custom (1.0.2)
271
+ lint_roller (~> 1.0)
272
+ rubocop (~> 1.50)
273
+ standard-performance (1.8.0)
274
+ lint_roller (~> 1.1)
275
+ rubocop-performance (~> 1.25.0)
227
276
  stringio (3.1.2)
228
277
  thor (1.3.2)
229
278
  timeout (0.4.2)
230
279
  tzinfo (2.0.6)
231
280
  concurrent-ruby (~> 1.0)
281
+ unicode-display_width (3.2.0)
282
+ unicode-emoji (~> 4.1)
283
+ unicode-emoji (4.1.0)
232
284
  uri (1.0.2)
233
285
  useragent (0.16.11)
234
286
  websocket-driver (0.7.6)
@@ -248,13 +300,16 @@ PLATFORMS
248
300
  x86_64-linux
249
301
 
250
302
  DEPENDENCIES
303
+ appraisal (~> 2.4)
251
304
  bundler (~> 2)
305
+ rbs (~> 3.0)
252
306
  rspec (~> 3)
253
307
  rspec_junit_formatter (~> 0.6)
254
308
  seed_builder!
255
309
  simplecov (~> 0.21)
256
310
  simplecov-cobertura (~> 2)
257
311
  sqlite3 (~> 2.4)
312
+ standard (~> 1.0)
258
313
 
259
314
  BUNDLED WITH
260
315
  2.5.20
data/README.md CHANGED
@@ -30,10 +30,31 @@ gem "seed_builder"
30
30
 
31
31
  ### Run seeds
32
32
 
33
+ Run all seeds:
34
+
33
35
  ```sh
34
36
  bin/rails db:seed
35
37
  ```
36
38
 
39
+ Or in code:
40
+
41
+ ```ruby
42
+ Rails.application.load_seed
43
+ ```
44
+
45
+ Run a specific seed file:
46
+
47
+ ```sh
48
+ bin/rails seed:run[create_users]
49
+ ```
50
+
51
+ You can specify the seed name in different formats:
52
+ - Class name: `create_users` (matches `20241206200111_create_users.rb`)
53
+ - Full name: `20241206200111_create_users`
54
+ - Timestamp: `20241206200111`
55
+
56
+ **Note:** If multiple seed files match the same name, you'll be prompted to use the full name with timestamp to avoid ambiguity. For example, if both `20241206200111_create_users.rb` and `20241206200112_create_users.rb` exist, running `bin/rails seed:run[create_users]` will show an error listing all matches and ask you to be more specific.
57
+
37
58
  ### Generate seed file
38
59
 
39
60
  ```sh
@@ -72,12 +93,24 @@ SeedBuilder.config.generate_spec = false
72
93
  SeedBuilder.config.use_seed_loader = false
73
94
  ```
74
95
 
96
+ ### Set custom logger
97
+
98
+ By default, SeedBuilder uses `Rails.logger` (or falls back to `Logger.new($stdout)` if Rails is not available). All seed-related log messages are tagged with `[seed]`.
99
+
100
+ To use a custom logger:
101
+
102
+ ```ruby
103
+ SeedBuilder.config.logger = MyCustomLogger.new
104
+ ```
105
+
106
+ The logger will be automatically wrapped with `ActiveSupport::TaggedLogging` if it doesn't already support tagging, ensuring all seed messages are tagged with `[seed]`.
107
+
75
108
  ## Specification checklist
76
109
 
77
110
  - [x] User can generate seed file under `db/seeds` directory with common format
78
111
  - [x] User can generate seed file with test script included
79
112
  - [x] User can run all seeds
80
- - [ ] User can run specific seed file
113
+ - [x] User can run specific seed file
81
114
 
82
115
  ## Limitations & explanations
83
116
 
@@ -86,15 +119,62 @@ SeedBuilder.config.use_seed_loader = false
86
119
  - Seeded data is not reversible, there is no point to implement it as logic can be complex and operations on data might lead to irreversible changes
87
120
  - Seed file is not a migration, although as good practice is to keep it idempotent, e.g. by checking uniqueness of seeded records
88
121
 
122
+ ## Development
123
+
124
+ ```bash
125
+ # Install dependencies
126
+ bundle install
127
+ bundle exec appraisal install
128
+
129
+ # Run tests for current Rails version
130
+ bundle exec rspec
131
+
132
+ # Run tests for all Rails versions (6.1, 7.2, 8.1)
133
+ bin/appraisals
134
+
135
+ # Run tests for specific Rails version
136
+ bin/appraisals rails-7.2
137
+
138
+ # Run tests for multiple versions
139
+ bin/appraisals rails-7.2 rails-8.1
140
+
141
+ # Or use appraisal directly
142
+ bundle exec appraisal rails-7.2 rspec
143
+
144
+ # Run linter
145
+ bundle exec standardrb --fix
146
+
147
+ # Check type signatures
148
+ bundle exec rbs validate
149
+ ```
150
+
151
+ ### Development: Using from Local Repository
152
+
153
+ When developing the gem or testing changes in your application, you can point your Gemfile to a local path:
154
+
155
+ ```ruby
156
+ # In your application's Gemfile
157
+ gem "seed_builder", path: "../seed_builder.rb"
158
+ ```
159
+
160
+ Then run:
161
+
162
+ ```bash
163
+ bundle install
164
+ ```
165
+
166
+ **Note:** When using `path:` in your Gemfile, Bundler will use the local gem directly. Changes you make to the gem code will be immediately available in your application without needing to rebuild or reinstall the gem. This is ideal for development and testing.
167
+
89
168
  ## Contributing
90
169
 
91
170
  Bug reports and pull requests are welcome on GitHub at <https://github.com/amkisko/seed_builder.rb>
92
171
 
93
172
  Contribution policy:
94
-
95
173
  - New features are not necessarily added to the gem
96
174
  - Pull request should have test coverage for affected parts
97
175
  - Pull request should have changelog entry
176
+
177
+ Review policy:
98
178
  - It might take up to 2 calendar weeks to review and merge critical fixes
99
179
  - It might take up to 6 calendar months to review and merge pull request
100
180
  - It might take up to 1 calendar year to review an issue
data/bin/appraisals ADDED
@@ -0,0 +1,99 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Run appraisal tests locally
4
+ # Usage:
5
+ # bin/appraisals # Run tests for all Rails versions
6
+ # bin/appraisals rails-7.0 # Run tests for Rails 7.0
7
+ # bin/appraisals rails-7.0 rails-8.0 # Run tests for specific versions
8
+ # bin/appraisals rails-7.0 rspec # Run rspec for Rails 7.0
9
+ # bin/appraisals rails-7.0 rake spec # Run rake spec for Rails 7.0
10
+
11
+ require "bundler/setup"
12
+
13
+ APPRAISALS_FILE = File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), "Appraisals")
14
+
15
+ unless File.exist?(APPRAISALS_FILE)
16
+ $stderr.puts "Error: Cannot find Appraisals file at #{APPRAISALS_FILE}"
17
+ exit 1
18
+ end
19
+
20
+ AVAILABLE_APPRAISALS = File.read(APPRAISALS_FILE, encoding: "UTF-8")
21
+ .scan(/appraise\s+"([^"]+)"/)
22
+ .flatten
23
+ .freeze
24
+
25
+ def usage
26
+ puts <<~USAGE
27
+ Usage: bin/appraisals [appraisal_name...] [command]
28
+
29
+ Examples:
30
+ bin/appraisals # Run rspec for all Rails versions
31
+ bin/appraisals rails-7.0 # Run rspec for Rails 7.0
32
+ bin/appraisals rails-7.0 rails-8.0 # Run rspec for Rails 7.0 and 8.0
33
+ bin/appraisals rails-7.0 rspec # Run rspec for Rails 7.0
34
+ bin/appraisals rails-7.0 rake spec # Run rake spec for Rails 7.0
35
+
36
+ Available appraisals: #{AVAILABLE_APPRAISALS.join(', ')}
37
+ USAGE
38
+ exit 1
39
+ end
40
+
41
+ def parse_args
42
+ args = ARGV.dup
43
+
44
+ # Handle help flags
45
+ if args.include?("--help") || args.include?("-h")
46
+ usage
47
+ end
48
+
49
+ return [AVAILABLE_APPRAISALS, ["rspec"]] if args.empty?
50
+
51
+ appraisals = []
52
+ command = []
53
+
54
+ args.each do |arg|
55
+ if AVAILABLE_APPRAISALS.include?(arg)
56
+ appraisals << arg
57
+ else
58
+ command << arg
59
+ end
60
+ end
61
+
62
+ appraisals = AVAILABLE_APPRAISALS if appraisals.empty?
63
+ command = ["rspec"] if command.empty?
64
+
65
+ [appraisals, command]
66
+ end
67
+
68
+ def run_appraisal(appraisal, command)
69
+ puts "\n" + "=" * 80
70
+ puts "Running #{appraisal} with: #{command.join(' ')}"
71
+ puts "=" * 80
72
+
73
+ cmd = ["bundle", "exec", "appraisal", appraisal] + command
74
+ system(*cmd)
75
+ end
76
+
77
+ appraisals, command = parse_args
78
+
79
+ unless appraisals.all? { |a| AVAILABLE_APPRAISALS.include?(a) }
80
+ puts "Error: Invalid appraisal(s)"
81
+ usage
82
+ end
83
+
84
+ results = {}
85
+ appraisals.each do |appraisal|
86
+ results[appraisal] = run_appraisal(appraisal, command)
87
+ end
88
+
89
+ puts "\n" + "=" * 80
90
+ puts "Summary"
91
+ puts "=" * 80
92
+ appraisals.each do |appraisal|
93
+ status = results[appraisal] ? "✓ PASSED" : "✗ FAILED"
94
+ puts "#{appraisal}: #{status}"
95
+ end
96
+
97
+ exit 0 if results.values.all?
98
+ exit 1
99
+
data/bin/seed ADDED
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Load Rails environment
4
+ require_relative "../config/environment" rescue nil
5
+
6
+ unless defined?(Rails)
7
+ puts "Error: Rails environment not loaded. Please run this from a Rails application root."
8
+ puts "Alternatively, use: bin/rails seed:run[SEED_NAME]"
9
+ exit 1
10
+ end
11
+
12
+ require_relative "../lib/seed_builder"
13
+
14
+ if ARGV.empty?
15
+ puts "Usage: bin/seed SEED_NAME"
16
+ puts ""
17
+ puts "Run a specific seed file by name."
18
+ puts ""
19
+ puts "Examples:"
20
+ puts " bin/seed create_users"
21
+ puts " bin/seed 20241206200111_create_users"
22
+ puts " bin/seed 20241206200111"
23
+ puts ""
24
+ puts "Note: This script must be run from a Rails application root."
25
+ puts " If multiple seed files match the name, use the full name with"
26
+ puts " timestamp to avoid ambiguity (e.g., 20241206200111_create_users)."
27
+ puts ""
28
+ puts "Alternatively, use: bin/rails seed:run[SEED_NAME]"
29
+ exit 1
30
+ end
31
+
32
+ seed_name = ARGV[0]
33
+
34
+ loader = SeedBuilder::Loader.new
35
+ loader.load_seed_file(seed_name)
36
+
@@ -2,7 +2,12 @@ module SeedBuilder
2
2
  class Config
3
3
  attr_writer :default_seeds_path
4
4
  def default_seeds_path
5
- @default_seeds_path ||= Rails.root.join("db/seeds.rb")
5
+ @default_seeds_path ||= "db/seeds.rb"
6
+ end
7
+
8
+ attr_writer :default_seeds_full_path
9
+ def default_seeds_full_path
10
+ @default_seeds_full_path ||= Rails.root.join(default_seeds_path)
6
11
  end
7
12
 
8
13
  attr_writer :seeds_path
@@ -21,22 +26,24 @@ module SeedBuilder
21
26
 
22
27
  attr_writer :load_default_seeds
23
28
  def load_default_seeds?
24
- @load_default_seeds.nil? ? true : @load_default_seeds
29
+ @load_default_seeds.nil? || @load_default_seeds
25
30
  end
26
31
 
27
32
  attr_writer :load_seeds
28
33
  def load_seeds?
29
- @load_seeds.nil? ? true : @load_seeds
34
+ @load_seeds.nil? || @load_seeds
30
35
  end
31
36
 
32
37
  attr_writer :generate_spec
33
38
  def generate_spec?
34
- @generate_spec.nil? ? true : @generate_spec
39
+ @generate_spec.nil? || @generate_spec
35
40
  end
36
41
 
37
42
  attr_writer :use_seed_loader
38
43
  def use_seed_loader?
39
- @use_seed_loader.nil? ? true : @use_seed_loader
44
+ @use_seed_loader.nil? || @use_seed_loader
40
45
  end
46
+
47
+ attr_accessor :logger
41
48
  end
42
49
  end