seed_helper 1.5.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/DEVELOPER_README.md +1 -1
- data/README.md +14 -1
- data/lib/seed_helper.rb +15 -0
- data/lib/seed_helper/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d78e46a77855c1697150a21e4776878db6a06d8
|
4
|
+
data.tar.gz: 262f395830e7fc2c7f59e1326e736bfc1b28b94f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76aa408a85f123da91dd65ad5fff144bf6995fc31d6dafe5dcf08cf5700a8321a5b139cebf49e1f5c20f058c808325182e724e4d0804f5fad13df44b8f875de9
|
7
|
+
data.tar.gz: 3ab7392f6ed85c998a4206a17186ea5e36182eb1c596c4b087cb4f8c219ce12e067a460d56245d7cb8f383ef3e612facbd8adf2c1491f18664c18ab3b0125bc4
|
data/DEVELOPER_README.md
CHANGED
data/README.md
CHANGED
@@ -8,7 +8,7 @@ The goal of SeedHelper is to provide some commonly required functionality to mak
|
|
8
8
|
|
9
9
|
## Dependencies
|
10
10
|
|
11
|
-
SeedHelper uses the [
|
11
|
+
SeedHelper uses the [colorize](https://github.com/fazibear/colorize) gem to present output.
|
12
12
|
|
13
13
|
## Example: Seed implementation
|
14
14
|
|
@@ -53,6 +53,19 @@ SeedHelper.create_seed_task(:create_users, [:create_roles]) do
|
|
53
53
|
end
|
54
54
|
```
|
55
55
|
|
56
|
+
## Example: Using FactoryGirl
|
57
|
+
|
58
|
+
If you don't want to provide specific attributes, you can use the `.bulk_create` function to do so. EG:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
# If MyClass.count > 0, an already created message will be shown
|
62
|
+
# If MyClass.count == 0, the block will be run
|
63
|
+
# If the block fails, you'll get a red error message with the exception printed out.
|
64
|
+
SeedHelper.bulk_create(MyClass) do
|
65
|
+
FactoryGirl.create_list(:my_class, 5)
|
66
|
+
end
|
67
|
+
```
|
68
|
+
|
56
69
|
## Example: Output
|
57
70
|
|
58
71
|
SeedHelper provides multiple methods for showing output that can be used outside of the `create_resource` method:
|
data/lib/seed_helper.rb
CHANGED
@@ -28,6 +28,21 @@ class SeedHelper
|
|
28
28
|
did_save
|
29
29
|
end
|
30
30
|
|
31
|
+
def self.bulk_create(klass, &creation_block)
|
32
|
+
klass_plural = klass.name.pluralize
|
33
|
+
|
34
|
+
if klass.any?
|
35
|
+
resource_already_exists(klass_plural)
|
36
|
+
else
|
37
|
+
begin
|
38
|
+
creation_block.call
|
39
|
+
success("Created #{klass_plural}")
|
40
|
+
rescue
|
41
|
+
error("Failed to create #{klass_plural}: #{$!}")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
31
46
|
private
|
32
47
|
|
33
48
|
def self.find_resource(resource_class, attributes)
|
data/lib/seed_helper/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seed_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordan Maguire
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|