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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2d3ee9a952a0c88ddac267118bcb6588ea3d3052
4
- data.tar.gz: faeb37e05d59b8825c83c7695cdf182856fb7ae6
3
+ metadata.gz: 7d78e46a77855c1697150a21e4776878db6a06d8
4
+ data.tar.gz: 262f395830e7fc2c7f59e1326e736bfc1b28b94f
5
5
  SHA512:
6
- metadata.gz: 0a7d700d2235c95bea1c67f700d708397419e40cc773760ad7381301c022e3c8bd43cb1088e1f222375fd2b60a66e8017448d10181a8921a9bbba94e5d3fdd89
7
- data.tar.gz: 55af5b02d9f43274a4012c8c23690657b5d00230a67ccb48c048db6a246bfb62321ecaee92834f86626a103aa498cf706c0a177ecdb6dcf50bb83c9cbe88c047
6
+ metadata.gz: 76aa408a85f123da91dd65ad5fff144bf6995fc31d6dafe5dcf08cf5700a8321a5b139cebf49e1f5c20f058c808325182e724e4d0804f5fad13df44b8f875de9
7
+ data.tar.gz: 3ab7392f6ed85c998a4206a17186ea5e36182eb1c596c4b087cb4f8c219ce12e067a460d56245d7cb8f383ef3e612facbd8adf2c1491f18664c18ab3b0125bc4
data/DEVELOPER_README.md CHANGED
@@ -13,7 +13,7 @@ gem install <gempath>
13
13
 
14
14
  Get into `irb`.
15
15
 
16
- Run
16
+ Run
17
17
 
18
18
  ```
19
19
  require 'seed_helper'
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 [colored](https://github.com/defunkt/colored) gem to present output.
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)
@@ -1,3 +1,3 @@
1
1
  class SeedHelper
2
- VERSION = "1.5.0"
2
+ VERSION = "1.6.0"
3
3
  end
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.5.0
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-01-08 00:00:00.000000000 Z
11
+ date: 2015-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize