rolemodel_sower 0.0.2 → 0.0.3
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 +26 -4
- data/examples/seeds/rolemodel_sower/organization.rb +1 -1
- data/examples/seeds/rolemodel_sower/user.rb +5 -5
- data/lib/rolemodel_sower/base.rb +2 -0
- data/lib/rolemodel_sower/version.rb +1 -1
- data/lib/rolemodel_sower.rb +7 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afa9c43c72ba7bef3fda89928296f16c18fedda9829b56b49aea9da7c8446e81
|
4
|
+
data.tar.gz: d2d0b1075dff10a91b0a27ca9409eeb58ae9fc7c32b59218ff8f0e83323babe0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52cf43b5235e4bb8a61ccc31fc7b18e41b4b1e71dd9c43582021a295ea52a5cb5ebd7bb5f1828c2345fa53132d38da362ef0672e0015c2bfa7454c57e2fc2d35
|
7
|
+
data.tar.gz: 4ae6ce8841263815b315ff3b57550f9a95af7e878c7011de407662daa9c41c8432c7de004c11399709f5b2befe71b3038340db68c30b457371e2d6b2c14bfcfa
|
data/README.md
CHANGED
@@ -68,9 +68,9 @@ module RolemodelSower
|
|
68
68
|
class User < RolemodelSower::Base
|
69
69
|
def load!
|
70
70
|
::User.find_or_create_by!(
|
71
|
-
first_name:
|
72
|
-
last_name:
|
73
|
-
email:
|
71
|
+
first_name: data[:first_name],
|
72
|
+
last_name: data[:last_name],
|
73
|
+
email: data[:last_name]
|
74
74
|
)
|
75
75
|
end
|
76
76
|
end
|
@@ -83,7 +83,13 @@ Seeds can be generated by calling the `seed!` method on `RolemodelSower`.
|
|
83
83
|
|
84
84
|
It takes one or more symbol arguments that correspond to sets of seed data and runs them in the order passed.
|
85
85
|
|
86
|
-
|
86
|
+
```ruby
|
87
|
+
RolemodelSower.seed!(
|
88
|
+
:users,
|
89
|
+
:organizations,
|
90
|
+
:facilities
|
91
|
+
)
|
92
|
+
```
|
87
93
|
|
88
94
|
If you want to add conditions to each run, you can separate out each call to seed.
|
89
95
|
|
@@ -103,6 +109,22 @@ RolemodelSower.setup do |config|
|
|
103
109
|
end
|
104
110
|
```
|
105
111
|
|
112
|
+
You can also specify the adapter when calling `seed!`. This will override the default adapter or what is set in the initializer.
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
RolemodelSower.seed!(
|
116
|
+
{ users: :csv },
|
117
|
+
:organizations,
|
118
|
+
{ facilities: :json }
|
119
|
+
)
|
120
|
+
```
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
RolemodelSower.seed!({ users: :csv }) if my_condition
|
124
|
+
RolemodelSower.seed!(:organizations) if other_condition
|
125
|
+
RolemodelSower.seed!({ facilities: :json }) if another_condition
|
126
|
+
```
|
127
|
+
|
106
128
|
## Development
|
107
129
|
|
108
130
|
To build the gem locally, run: `gem build rolemodel_sower.gemspec`
|
@@ -4,12 +4,12 @@ module RolemodelSower
|
|
4
4
|
class User < RolemodelSower::Base
|
5
5
|
def load!
|
6
6
|
user = ::User.create_with(
|
7
|
-
first_name:
|
8
|
-
last_name:
|
9
|
-
password:
|
10
|
-
password_confirmation:
|
7
|
+
first_name: data[:first_name],
|
8
|
+
last_name: data[:last_name],
|
9
|
+
password: data[:password],
|
10
|
+
password_confirmation: data[:password],
|
11
11
|
organization: ::Organization.first,
|
12
|
-
).find_or_create_by! email:
|
12
|
+
).find_or_create_by! email: data[:email]
|
13
13
|
|
14
14
|
# Any models can be affected here.
|
15
15
|
::Profile.find_or_create_by!(user: user)
|
data/lib/rolemodel_sower/base.rb
CHANGED
data/lib/rolemodel_sower.rb
CHANGED
@@ -25,10 +25,15 @@ module RolemodelSower
|
|
25
25
|
|
26
26
|
def self.seed!(*seed_names)
|
27
27
|
seed_names.each do |seed_name|
|
28
|
+
current_seed_name = seed_name.try(:keys)&.first || seed_name
|
29
|
+
current_adapter = seed_name.try(:values)&.first || adapter
|
30
|
+
pluralized_name = current_seed_name.to_s.classify
|
31
|
+
|
28
32
|
logger = Logger.new($stdout)
|
29
|
-
pluralized_name = seed_name.to_s.classify
|
30
33
|
logger.info "Seeding #{pluralized_name}..." if Rails.env.development?
|
31
|
-
|
34
|
+
|
35
|
+
"RolemodelSower::Adapters::#{current_adapter.to_s.upcase}".constantize.all(current_seed_name).each(&:load!)
|
36
|
+
|
32
37
|
logger.info "Seeding #{pluralized_name}... done" if Rails.env.development?
|
33
38
|
end
|
34
39
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rolemodel_sower
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Walton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A Ruby gem to simplify Seed data creation for Rails applications.
|
14
14
|
email: consult@rolemodelsoftware.com
|