planter 0.0.5 → 0.0.6
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 +4 -4
- data/README.md +4 -4
- data/lib/planter.rb +9 -9
- data/lib/planter/config.rb +5 -5
- data/lib/planter/version.rb +48 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95ab85b49c50ea3b7ee077d4225083884558ae89c6fa5b2ea4e9410284f890eb
|
4
|
+
data.tar.gz: 2fd36b19ab5064d681323eb5f7e73a95cf710b7af8a587031c84b7175610cfbe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa74216b4529bcb3d21ccd697574c175ad7dd641d477921108ff9949e1ab9a9537cf6f4847b6e2aaadeb91e8aecedc6afec243c72250d9b77cce1da0e4926580
|
7
|
+
data.tar.gz: 9b9cb5dd5a29b8a66c8cd9a6c49d5192c1395a5d935a98628928f65babcd709c2a6480ed356bf2f575e0710856a214025efdf91942acf3fe034a39a1369f302a
|
data/README.md
CHANGED
@@ -13,7 +13,7 @@ db:seed` task.
|
|
13
13
|
Features include:
|
14
14
|
|
15
15
|
- Seed tables from CSV files, an array of hashes, or custom methods.
|
16
|
-
-
|
16
|
+
- Call specific seeders with `rails db:seed SEEDERS=users,addresses`.
|
17
17
|
- Control the number of records being created.
|
18
18
|
- Seed associations.
|
19
19
|
|
@@ -42,14 +42,14 @@ $ gem install planter
|
|
42
42
|
Let's assume you'd like to seed your `users` table.
|
43
43
|
|
44
44
|
To get started, simply add the following to your `db/seeds.rb` file. Note that
|
45
|
-
the `config.
|
45
|
+
the `config.seeders` should be an array of the seeders to use. They should be in
|
46
46
|
the correct order to successfully seed the tables when considering associations.
|
47
47
|
|
48
48
|
```ruby
|
49
49
|
require 'planter'
|
50
50
|
|
51
51
|
Planter.configure do |config|
|
52
|
-
config.
|
52
|
+
config.seeders = %i[ users ]
|
53
53
|
end
|
54
54
|
|
55
55
|
Planter.seed
|
@@ -179,7 +179,7 @@ require 'planter'
|
|
179
179
|
Planter.configure do |config|
|
180
180
|
config.seeders_directory = 'db/seeder_classes'
|
181
181
|
config.csv_files_directory = 'db/csvs'
|
182
|
-
config.
|
182
|
+
config.seeders = %i[
|
183
183
|
users
|
184
184
|
addresses
|
185
185
|
]
|
data/lib/planter.rb
CHANGED
@@ -93,7 +93,7 @@ module Planter
|
|
93
93
|
#
|
94
94
|
# @example
|
95
95
|
# Planter.configure do |app_seeder|
|
96
|
-
# app_seeder.
|
96
|
+
# app_seeder.seeders = %i[users]
|
97
97
|
# app_seeder.seeders_directory = 'db/seeds'
|
98
98
|
# app_seeder.csv_files_directory = 'db/seed_files'
|
99
99
|
# end
|
@@ -102,18 +102,18 @@ module Planter
|
|
102
102
|
end
|
103
103
|
|
104
104
|
##
|
105
|
-
# This is the method to call from your +db/seeds.rb+. It
|
106
|
-
# listed in +Planter.config.
|
107
|
-
# runtime, you can set the +
|
108
|
-
# comma-separated list of
|
105
|
+
# This is the method to call from your +db/seeds.rb+. It callse the seeders
|
106
|
+
# listed in +Planter.config.seeders+. To call specific seeders at
|
107
|
+
# runtime, you can set the +SEEDERS+ environmental variable to a
|
108
|
+
# comma-separated list of seeders.
|
109
109
|
#
|
110
110
|
# @example
|
111
|
-
# rails db:seed
|
111
|
+
# rails db:seed SEEDERS=users,accounts
|
112
112
|
def self.seed
|
113
|
-
|
114
|
-
raise RuntimeError, 'No
|
113
|
+
seeders = ENV['SEEDERS']&.split(',') || config.seeders&.map(&:to_s)
|
114
|
+
raise RuntimeError, 'No seeders specified; nothing to do' unless seeders&.any?
|
115
115
|
|
116
|
-
|
116
|
+
seeders.each do |table|
|
117
117
|
require Rails.root.join(config.seeders_directory, "#{table}_seeder.rb").to_s
|
118
118
|
puts "Seeding #{table}" unless config.quiet
|
119
119
|
"#{table.camelize}Seeder".constantize.new.seed
|
data/lib/planter/config.rb
CHANGED
@@ -5,7 +5,7 @@ module Planter
|
|
5
5
|
# Configure the application seeder.
|
6
6
|
#
|
7
7
|
# @example
|
8
|
-
# Planter.configure { |seeder| seeder.
|
8
|
+
# Planter.configure { |seeder| seeder.seeders = %i[users] }
|
9
9
|
class Config
|
10
10
|
##
|
11
11
|
# Tell the application where the seeder classes are kept. Must be a path
|
@@ -26,13 +26,13 @@ module Planter
|
|
26
26
|
attr_accessor :csv_files_directory
|
27
27
|
|
28
28
|
##
|
29
|
-
# Tell the application what
|
30
|
-
# order, and can be strings or symbols.
|
29
|
+
# Tell the application what seeders exist. Elements should be in the correct
|
30
|
+
# order to seed the tables successfully, and can be strings or symbols.
|
31
31
|
#
|
32
|
-
# @param [Array]
|
32
|
+
# @param [Array] seeders
|
33
33
|
#
|
34
34
|
# @return [Array]
|
35
|
-
attr_accessor :
|
35
|
+
attr_accessor :seeders
|
36
36
|
|
37
37
|
##
|
38
38
|
# When true, don't print output when seeding.
|
data/lib/planter/version.rb
CHANGED
@@ -1,7 +1,54 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Planter
|
4
|
+
##
|
5
|
+
# Module that contains all gem version information. Follows semantic
|
6
|
+
# versioning. Read: https://semver.org/
|
7
|
+
module Version
|
8
|
+
##
|
9
|
+
# Major version.
|
10
|
+
#
|
11
|
+
# @return [Integer]
|
12
|
+
MAJOR = 0
|
13
|
+
|
14
|
+
##
|
15
|
+
# Minor version.
|
16
|
+
#
|
17
|
+
# @return [Integer]
|
18
|
+
MINOR = 0
|
19
|
+
|
20
|
+
##
|
21
|
+
# Patch version.
|
22
|
+
#
|
23
|
+
# @return [Integer]
|
24
|
+
PATCH = 6
|
25
|
+
|
26
|
+
##
|
27
|
+
# Version as +[MAJOR, MINOR, PATCH]+
|
28
|
+
#
|
29
|
+
# @return [Array]
|
30
|
+
def self.to_a
|
31
|
+
[MAJOR, MINOR, PATCH]
|
32
|
+
end
|
33
|
+
|
34
|
+
##
|
35
|
+
# Version as +MAJOR.MINOR.PATCH+
|
36
|
+
#
|
37
|
+
# @return [String]
|
38
|
+
def self.to_s
|
39
|
+
to_a.join('.')
|
40
|
+
end
|
41
|
+
|
42
|
+
##
|
43
|
+
# Version as +{major: MAJOR, minor: MINOR, patch: PATCH}+
|
44
|
+
#
|
45
|
+
# @return [Hash]
|
46
|
+
def self.to_h
|
47
|
+
Hash[%i[major minor patch].zip(to_a)]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
4
51
|
##
|
5
52
|
# Gem version, semantic.
|
6
|
-
VERSION =
|
53
|
+
VERSION = Version.to_s.freeze
|
7
54
|
end
|