data_seeder 0.0.3 → 0.0.4
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 +16 -3
- data/lib/data_seeder/loader.rb +5 -0
- data/lib/data_seeder/version.rb +1 -1
- data/test/dummy/log/test.log +10665 -0
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76bc082c7fc3988e2b2e2dfb3f7081355b0e8c9f
|
4
|
+
data.tar.gz: 19d93dc6c98f85efff3e346765f95f9919585977
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b3ba7a3a353df0105a099b52f4927663b7c7269b85c649a5ec05f3da4dfc0d12c6584d0453228380b6a87b1bea4546975e96b9a182efe17c328dff9b7f3f477
|
7
|
+
data.tar.gz: 17c5650a82004b40c9d0006e89862df230f62c1eadc3eb2f84efa287c2bc3b8fe7443607dbb8b12336f673b6b0cd2d7520c10bfd5ac557c59cbb28662e146fe4
|
data/README.md
CHANGED
@@ -48,6 +48,20 @@ the key_attribute says that it will use the 'code' attribute to lookup existing
|
|
48
48
|
and the line function
|
49
49
|
defines how the line is converted to an attribute hash defining the instance.
|
50
50
|
|
51
|
+
Since the first line can get a little busy with config information, you can also store your config in a
|
52
|
+
separate .cfg file with the same name. This contents of this file should eval to a hash. The above config line would be
|
53
|
+
equivalent to a db/seed/countries.cfg file with the following:
|
54
|
+
|
55
|
+
{
|
56
|
+
key_attribute: :'code',
|
57
|
+
line: ->(attr) {
|
58
|
+
{
|
59
|
+
code: line[0,2],
|
60
|
+
name: line[3...-1]
|
61
|
+
}
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
51
65
|
Running rake db:seed will result in the following output:
|
52
66
|
|
53
67
|
# rake db:seed
|
@@ -196,9 +210,6 @@ YAML should allow loading as either array or hash. (currently only does hash)
|
|
196
210
|
|
197
211
|
CSV should have options such as only: and except: for using/skipping the specified header columns.
|
198
212
|
|
199
|
-
Allow multi-line config statement in seed file header? Would somehow need to mark it as such via end-of-line mark or
|
200
|
-
beginning-of-line mark or maybe use '#-' or '#%' for all command-type lines?
|
201
|
-
|
202
213
|
The structure.sql caching within rails uses the file timestamp to determine whether to prepare the test database. This
|
203
214
|
is error prone and forces you to do a 'touch db/structure.sql' to get around the not getting reloaded problem. Should
|
204
215
|
I add a utility to override this rails implementation with a sha-based one like the seed files use? (or am I the only
|
@@ -227,6 +238,8 @@ Allow config-driven initialization so that we could require: false in the Gemfil
|
|
227
238
|
|
228
239
|
Add depends_on option.
|
229
240
|
|
241
|
+
Document options (key_attribute, line, postprocess, etc)
|
242
|
+
|
230
243
|
Meta
|
231
244
|
----
|
232
245
|
|
data/lib/data_seeder/loader.rb
CHANGED
@@ -100,6 +100,11 @@ module DataSeeder
|
|
100
100
|
key = attr[@key_attribute.to_s] || attr[@key_attribute.to_sym]
|
101
101
|
raise "No #{@key_attribute} in #{attr.inspect}" unless key
|
102
102
|
end
|
103
|
+
if method = @file_config[:postprocess]
|
104
|
+
method.call(attr)
|
105
|
+
elsif self.klass.respond_to?(:data_seeder_postprocess)
|
106
|
+
self.klass.send(:data_seeder_postprocess, attr)
|
107
|
+
end
|
103
108
|
@old_keys.delete(key.to_s)
|
104
109
|
model = self.klass.find_or_initialize_by(@key_attribute => key)
|
105
110
|
model.attributes = attr
|
data/lib/data_seeder/version.rb
CHANGED