rolemodel_sower 0.0.1 → 0.0.2
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 +41 -3
- data/examples/seeds/rolemodel_sower/organization.rb +2 -2
- data/examples/seeds/rolemodel_sower/user.rb +2 -2
- data/lib/generators/rolemodel_sower/USAGE +1 -1
- data/lib/generators/rolemodel_sower/templates/config/initializers/rolemodel_sower.rb +3 -0
- data/lib/rolemodel_sower/adapters/base.rb +1 -1
- data/lib/rolemodel_sower/version.rb +1 -1
- data/lib/rolemodel_sower.rb +3 -0
- 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: 9c9302216ddd04b2b1f6f622b07a95fc5bbebf790af4f8193ab220319c22482b
|
|
4
|
+
data.tar.gz: 0caae91d305535041c4d44ca60a2ef0d160906305f3e6cd5d630c109c8d4d1cf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d4b6b1bc630736cd6fd22fd93052e957ee45aa3ff06a414d3334c4cbda86512255ef9ee5e36cdba9ce03b16881dc3ab7ddb86b9caba09f20a7f3581f2475f14d
|
|
7
|
+
data.tar.gz: 35ac92d81fef1e528301f7852d37e8dc1760d041719b77da8073aab04576d33bbf4de3dbf4ea8d5dfc03bf1e4629b12b248819df4917821d2384ec9e3056f0b8
|
data/README.md
CHANGED
|
@@ -30,9 +30,17 @@ Seed data is created by placing files in the `db/rolemodel_sower_data` directory
|
|
|
30
30
|
|
|
31
31
|
`db/rolemodel_sower_data/users.json`
|
|
32
32
|
|
|
33
|
+
The seed data directory can be configured in the initializer generated by the install generator.
|
|
34
|
+
|
|
35
|
+
```ruby
|
|
36
|
+
RolemodelSower.setup do |config|
|
|
37
|
+
config.data_path = 'db/seed_data'
|
|
38
|
+
end
|
|
39
|
+
```
|
|
40
|
+
|
|
33
41
|
### Translating Seed Data
|
|
34
42
|
|
|
35
|
-
You will need to define a rolemodel_sower file to take the data parsed from your seed data and
|
|
43
|
+
You will need to define a rolemodel_sower file to take the data parsed from your seed data and create the records in your database.
|
|
36
44
|
|
|
37
45
|
Sower files should be created in `app/seeds/rolemodel_sower`. The files should be named after the model they are creating data for. For example, a file named `user.rb` would create seed data for the `User` model.
|
|
38
46
|
|
|
@@ -57,7 +65,7 @@ In `app/seeds/rolemodel_sower/user.rb`
|
|
|
57
65
|
# frozen_string_literal: true
|
|
58
66
|
|
|
59
67
|
module RolemodelSower
|
|
60
|
-
class User <
|
|
68
|
+
class User < RolemodelSower::Base
|
|
61
69
|
def load!
|
|
62
70
|
::User.find_or_create_by!(
|
|
63
71
|
first_name: @data[:first_name],
|
|
@@ -73,10 +81,18 @@ end
|
|
|
73
81
|
|
|
74
82
|
Seeds can be generated by calling the `seed!` method on `RolemodelSower`.
|
|
75
83
|
|
|
76
|
-
It takes one or more symbol arguments that correspond to sets of seed data and runs
|
|
84
|
+
It takes one or more symbol arguments that correspond to sets of seed data and runs them in the order passed.
|
|
77
85
|
|
|
78
86
|
`RolemodelSower.seed!(:users, :organizations, :facilities)`
|
|
79
87
|
|
|
88
|
+
If you want to add conditions to each run, you can separate out each call to seed.
|
|
89
|
+
|
|
90
|
+
```ruby
|
|
91
|
+
RolemodelSower.seed!(:users) if my_condition
|
|
92
|
+
RolemodelSower.seed!(:organizations) if other_condition
|
|
93
|
+
RolemodelSower.seed!(:facilities) if another_condition
|
|
94
|
+
```
|
|
95
|
+
|
|
80
96
|
## Adapters
|
|
81
97
|
|
|
82
98
|
RolemodelSower defaults to loading yml files, but can be configured to load json, csv, or tsv files. This can be configured in `config/initializers/rolemodel_sower.rb`. (Can be generated by running `rails generate rolemodel_sower:install`)
|
|
@@ -86,3 +102,25 @@ RolemodelSower.setup do |config|
|
|
|
86
102
|
config.adapter = :json
|
|
87
103
|
end
|
|
88
104
|
```
|
|
105
|
+
|
|
106
|
+
## Development
|
|
107
|
+
|
|
108
|
+
To build the gem locally, run: `gem build rolemodel_sower.gemspec`
|
|
109
|
+
|
|
110
|
+
To test the gem locally, use the path option in your Gemfile:
|
|
111
|
+
|
|
112
|
+
```ruby
|
|
113
|
+
gem 'rolemodel_sower', path: '../rolemodel_sower'
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Publishing
|
|
117
|
+
|
|
118
|
+
Make sure you are an owner of the gem.
|
|
119
|
+
|
|
120
|
+
You also need to be signed in to rubygmes by running:
|
|
121
|
+
|
|
122
|
+
`gem signin`
|
|
123
|
+
|
|
124
|
+
To publish, run:
|
|
125
|
+
|
|
126
|
+
`gem push rolemodel_sower-{major.minor.patch}.gem`
|
|
@@ -12,7 +12,7 @@ module RolemodelSower
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def self.path(seed_name)
|
|
15
|
-
Rails.root.join("
|
|
15
|
+
Rails.root.join("#{RolemodelSower.data_path}/#{seed_name.to_s.pluralize}#{file_extension}")
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def self.class_name(seed_name)
|
data/lib/rolemodel_sower.rb
CHANGED
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.2
|
|
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-07-
|
|
11
|
+
date: 2023-07-30 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
|