data_seeder 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b2dae3dbaee3c5818f38a32bfb2d03864ee95159
4
- data.tar.gz: 27a83d1da43cd0b6a99f0b696c5fc736abb85ab8
3
+ metadata.gz: 76bc082c7fc3988e2b2e2dfb3f7081355b0e8c9f
4
+ data.tar.gz: 19d93dc6c98f85efff3e346765f95f9919585977
5
5
  SHA512:
6
- metadata.gz: 3798e1d859d78df4e187e5a08fdd21a9e1ee0bfaeb0ff5c3542ed385a1094c8433a153b5656b37765109167851b6130d8073085830ec368d879af7f7d83eb9b2
7
- data.tar.gz: 554116d29bc99194af989002f13bbb71356a5973908e3a65b69e85dfe08a3b3bad3c5b9973a12ea8cf22a434dbf2c6bfa226ad498f2f4515d28245f4cefe6dbb
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
 
@@ -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
@@ -1,3 +1,3 @@
1
1
  module DataSeeder
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end