planter 0.4.2 → 1.0.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 +4 -4
- data/README.md +129 -40
- data/lib/generators/planter/adapter_generator.rb +19 -14
- data/lib/generators/planter/initializer_generator.rb +7 -1
- data/lib/generators/planter/seeder_generator.rb +109 -9
- data/lib/planter/adapters/active_record.rb +106 -31
- data/lib/planter/config.rb +2 -2
- data/lib/planter/csv_data_source.rb +54 -0
- data/lib/planter/record_attributes.rb +113 -0
- data/lib/planter/seed_context.rb +83 -0
- data/lib/planter/seeder.rb +70 -121
- data/lib/planter/validator.rb +296 -0
- data/lib/planter/version.rb +3 -3
- data/lib/planter.rb +16 -2
- data/lib/tasks/planter_tasks.rake +31 -5
- metadata +5 -1
data/lib/planter.rb
CHANGED
|
@@ -5,7 +5,11 @@ require "erb"
|
|
|
5
5
|
require "planter/version"
|
|
6
6
|
require "planter/railtie"
|
|
7
7
|
require "planter/config"
|
|
8
|
+
require "planter/seed_context"
|
|
9
|
+
require "planter/csv_data_source"
|
|
10
|
+
require "planter/record_attributes"
|
|
8
11
|
require "planter/seeder"
|
|
12
|
+
require "planter/validator"
|
|
9
13
|
|
|
10
14
|
##
|
|
11
15
|
# The main module for the plugin. It nicely wraps the +Planter::Config+ class
|
|
@@ -59,9 +63,9 @@ module Planter
|
|
|
59
63
|
end
|
|
60
64
|
|
|
61
65
|
##
|
|
62
|
-
# This is the method to call from your +db/seeds.rb+. It
|
|
66
|
+
# This is the method to call from your +db/seeds.rb+. It calls the seeders
|
|
63
67
|
# listed in +Planter.config.seeders+. To call specific seeders at runtime,
|
|
64
|
-
# you can set the +SEEDERS+
|
|
68
|
+
# you can set the +SEEDERS+ environment variable to a comma-separated list
|
|
65
69
|
# of seeders, like +rails db:seed SEEDERS=users,accounts+.
|
|
66
70
|
#
|
|
67
71
|
# @example
|
|
@@ -80,4 +84,14 @@ module Planter
|
|
|
80
84
|
"#{s.camelize}Seeder".constantize.new.seed
|
|
81
85
|
end
|
|
82
86
|
end
|
|
87
|
+
|
|
88
|
+
##
|
|
89
|
+
# Validate the configured seed plan without creating records. This checks
|
|
90
|
+
# seeder files, seeder classes, built-in seeding method configuration, CSV
|
|
91
|
+
# headers where possible, and the configured adapter API.
|
|
92
|
+
#
|
|
93
|
+
# @return [Planter::Validator::Result]
|
|
94
|
+
def validate
|
|
95
|
+
Planter::Validator.new.validate
|
|
96
|
+
end
|
|
83
97
|
end
|
|
@@ -1,13 +1,39 @@
|
|
|
1
1
|
require "planter"
|
|
2
2
|
|
|
3
3
|
namespace :planter do
|
|
4
|
+
apply_directory_overrides = lambda do
|
|
5
|
+
if ENV["SEEDERS_DIRECTORY"]
|
|
6
|
+
Planter.config.seeders_directory = ENV["SEEDERS_DIRECTORY"]
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
if ENV["CSV_FILES_DIRECTORY"]
|
|
10
|
+
Planter.config.csv_files_directory = ENV["CSV_FILES_DIRECTORY"]
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
4
14
|
desc "Seed application. Use this to keep planter separate from db:seed"
|
|
5
15
|
task seed: :environment do
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
ENV["SEEDERS_DIRECTORY"] && config.seeders_directory = ENV["SEEDERS_DIRECTORY"]
|
|
9
|
-
ENV["CSV_FILES_DIRECTORY"] && config.csv_files_directory = ENV["CSV_FILES_DIRECTORY"]
|
|
10
|
-
end
|
|
16
|
+
# NOTE: the seed method already looks for ENV['SEEDERS']
|
|
17
|
+
apply_directory_overrides.call
|
|
11
18
|
Planter.seed
|
|
12
19
|
end
|
|
20
|
+
|
|
21
|
+
desc "Validate Planter configuration without creating records"
|
|
22
|
+
task validate: :environment do
|
|
23
|
+
apply_directory_overrides.call
|
|
24
|
+
result = Planter.validate
|
|
25
|
+
|
|
26
|
+
result.warnings.each { |warning| warn "WARNING: #{warning}" }
|
|
27
|
+
result.errors.each { |error| warn "ERROR: #{error}" }
|
|
28
|
+
|
|
29
|
+
if result.success?
|
|
30
|
+
puts(
|
|
31
|
+
result.warnings.empty? ?
|
|
32
|
+
"Planter validation passed." :
|
|
33
|
+
"Planter validation completed with warnings."
|
|
34
|
+
)
|
|
35
|
+
else
|
|
36
|
+
abort "Planter validation failed."
|
|
37
|
+
end
|
|
38
|
+
end
|
|
13
39
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: planter
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Evan Gray
|
|
@@ -102,8 +102,12 @@ files:
|
|
|
102
102
|
- lib/planter.rb
|
|
103
103
|
- lib/planter/adapters/active_record.rb
|
|
104
104
|
- lib/planter/config.rb
|
|
105
|
+
- lib/planter/csv_data_source.rb
|
|
105
106
|
- lib/planter/railtie.rb
|
|
107
|
+
- lib/planter/record_attributes.rb
|
|
108
|
+
- lib/planter/seed_context.rb
|
|
106
109
|
- lib/planter/seeder.rb
|
|
110
|
+
- lib/planter/validator.rb
|
|
107
111
|
- lib/planter/version.rb
|
|
108
112
|
- lib/tasks/planter_tasks.rake
|
|
109
113
|
homepage: https://github.com/evanthegrayt/planter
|