planter 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -4
- data/lib/generators/planter/initializer_generator.rb +1 -1
- data/lib/planter/seeder.rb +18 -3
- data/lib/planter/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 259e8d195e480b9b5f16d67ee729d822f9c67131650997d2c95958f1356d76ab
|
4
|
+
data.tar.gz: f2722663f8f1628268208dd0e35da17507a62b339e0dc45004ba16c59f0879b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3598c5503a8fef0db359b9ba6bcbd29e22ca3566e6f9ec0ebf0daa9a23961a227cad94478178b700d7b696b638fed51ea9bb61c5a71fb7a1874eb0765c6334ec
|
7
|
+
data.tar.gz: 92d6beec3c0c16fb9dd03d3b26fe6aadf94e28298f058795508c18863e6e41c0f3034c254eb995804d59f211c14bbdc1565848260026b0cf4c2e87f9bd1f7f6e
|
data/README.md
CHANGED
@@ -19,10 +19,12 @@ Features include:
|
|
19
19
|
You can view the documentation [here](https://evanthegrayt.github.io/planter/).
|
20
20
|
|
21
21
|
## Installation
|
22
|
-
Add
|
22
|
+
Add the following line to your application's Gemfile. Because this plugin is
|
23
|
+
currently a pre-release version, it's recommended to lock it to a specific
|
24
|
+
version, as breaking changes may occur, even at the patch level.
|
23
25
|
|
24
26
|
```ruby
|
25
|
-
gem 'planter'
|
27
|
+
gem 'planter', '0.0.10'
|
26
28
|
```
|
27
29
|
|
28
30
|
And then execute:
|
@@ -51,7 +53,7 @@ Planter.configure do |config|
|
|
51
53
|
# The list of seeders. These files are stored in the
|
52
54
|
# config.seeders_directory, which can be changed below. When a new
|
53
55
|
# seeder is generated, it will be appended to the bottom of this
|
54
|
-
# list. If the order is incorrect, you'll need to adjust
|
56
|
+
# list. If the order is incorrect, you'll need to adjust it.
|
55
57
|
# Just be sure to keep the ending bracket on its own line, or the
|
56
58
|
# generator won't know where to put new elements.
|
57
59
|
config.seeders = %i[
|
@@ -138,7 +140,7 @@ file name. For example, `users.csv.erb`. Note that lines starting with `<%` and
|
|
138
140
|
ending with `%>` will not be considered rows, so you can use `ERB` rows to set
|
139
141
|
values. For example:
|
140
142
|
|
141
|
-
```
|
143
|
+
```
|
142
144
|
email,login_attempts
|
143
145
|
<% count = 1 %>
|
144
146
|
test2@example.com,<%= count += 1 %>
|
@@ -12,7 +12,7 @@ module Planter
|
|
12
12
|
# The list of seeders. These files are stored in the
|
13
13
|
# config.seeders_directory, which can be changed below. When a new
|
14
14
|
# seeder is generated, it will be appended to the bottom of this
|
15
|
-
# list. If the order is incorrect, you'll need to adjust
|
15
|
+
# list. If the order is incorrect, you'll need to adjust it.
|
16
16
|
# Just be sure to keep the ending bracket on its own line, or the
|
17
17
|
# generator won't know where to put new elements.
|
18
18
|
config.seeders = %i[
|
data/lib/planter/seeder.rb
CHANGED
@@ -138,6 +138,7 @@ module Planter
|
|
138
138
|
parent_model: nil,
|
139
139
|
association: nil,
|
140
140
|
csv_name: nil,
|
141
|
+
erb_trim_mode: nil,
|
141
142
|
unique_columns: nil
|
142
143
|
)
|
143
144
|
if !SEEDING_METHODS.include?(method.intern)
|
@@ -152,6 +153,7 @@ module Planter
|
|
152
153
|
@parent_model = parent_model
|
153
154
|
@association = @parent_model && (association || determine_association)
|
154
155
|
@csv_file = determine_csv_filename(csv_name) if @seeding_method == :csv
|
156
|
+
@erb_trim_mode = erb_trim_mode
|
155
157
|
@unique_columns =
|
156
158
|
case unique_columns
|
157
159
|
when String, Symbol then [unique_columns.intern]
|
@@ -260,6 +262,14 @@ module Planter
|
|
260
262
|
@unique_columns ||= self.class.instance_variable_get('@unique_columns')
|
261
263
|
end
|
262
264
|
|
265
|
+
##
|
266
|
+
# Trim mode for ERB when parsing CSVs.
|
267
|
+
#
|
268
|
+
# @return [String, nil]
|
269
|
+
def erb_trim_mode
|
270
|
+
@erb_trim_mode ||= self.class.instance_variable_get('@erb_trim_mode')
|
271
|
+
end
|
272
|
+
|
263
273
|
##
|
264
274
|
# Creates records from the +data+ attribute.
|
265
275
|
def create_records
|
@@ -309,7 +319,7 @@ module Planter
|
|
309
319
|
when :csv
|
310
320
|
contents = ::File.read(csv_file)
|
311
321
|
if csv_file.end_with?('.erb')
|
312
|
-
contents = ERB.new(contents, trim_mode:
|
322
|
+
contents = ERB.new(contents, trim_mode: erb_trim_mode).result(binding)
|
313
323
|
end
|
314
324
|
|
315
325
|
@data ||= ::CSV.parse(
|
@@ -323,8 +333,13 @@ module Planter
|
|
323
333
|
end
|
324
334
|
|
325
335
|
def split_record(rec) # :nodoc:
|
326
|
-
|
327
|
-
|
336
|
+
u = {}
|
337
|
+
model.constantize.reflect_on_all_associations.map(&:name).each do |a|
|
338
|
+
u[a] = rec.delete(a) if rec.key?(a)
|
339
|
+
end
|
340
|
+
return [u, rec] unless unique_columns
|
341
|
+
|
342
|
+
unique_columns.each { |c, h| h[c] = rec.delete(c) }
|
328
343
|
[u, rec]
|
329
344
|
end
|
330
345
|
end
|
data/lib/planter/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: planter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evan Gray
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -57,7 +57,7 @@ metadata:
|
|
57
57
|
homepage_uri: https://github.com/evanthegrayt/planter
|
58
58
|
source_code_uri: https://github.com/evanthegrayt/planter
|
59
59
|
documentation_uri: https://evanthegrayt.github.io/planter/
|
60
|
-
post_install_message:
|
60
|
+
post_install_message:
|
61
61
|
rdoc_options: []
|
62
62
|
require_paths:
|
63
63
|
- lib
|
@@ -72,8 +72,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
72
|
- !ruby/object:Gem::Version
|
73
73
|
version: '0'
|
74
74
|
requirements: []
|
75
|
-
rubygems_version: 3.2.
|
76
|
-
signing_key:
|
75
|
+
rubygems_version: 3.2.22
|
76
|
+
signing_key:
|
77
77
|
specification_version: 4
|
78
78
|
summary: Framework for seeding rails applications.
|
79
79
|
test_files: []
|