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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7a83f928ff615025f32fe7060888fbf45508825a44593de8752447324d9c3b53
4
- data.tar.gz: cd767fdd458dfd25c62a87a247068d467e3b13bf4cfbbb612b8e6fd4f96356b6
3
+ metadata.gz: 9c9302216ddd04b2b1f6f622b07a95fc5bbebf790af4f8193ab220319c22482b
4
+ data.tar.gz: 0caae91d305535041c4d44ca60a2ef0d160906305f3e6cd5d630c109c8d4d1cf
5
5
  SHA512:
6
- metadata.gz: 701c5bfc6fab930f3c0038420e3b24c8828a6677512af4314cea13dac80d808ea798773036c336911419526ea0c1c54ea9a505467ad88947dae2844278d2ef64
7
- data.tar.gz: 26aef1405e5a63fdf383f5ea257de0e7ba9c218f70ec5b4e3f686ddecb8c982dbc264b55e9d57f9208e5fed090325232180dca65fc3acf2963b7488a4a8587e1
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 turn create the records in your database.
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 < Sower::Base
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 then in the order passed.
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`
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Sower
4
- class Organization < Sower::Base
3
+ module RolemodelSower
4
+ class Organization < RolemodelSower::Base
5
5
  def load!
6
6
  ::Organization.find_or_create_by! name: @data[:name]
7
7
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Sower
4
- class User < Sower::Base
3
+ module RolemodelSower
4
+ class User < RolemodelSower::Base
5
5
  def load!
6
6
  user = ::User.create_with(
7
7
  first_name: @data[:first_name],
@@ -1,3 +1,3 @@
1
1
  To copy a Sower initializer to your Rails App, with some configuration values, just do:
2
2
 
3
- rails generate sower:install
3
+ rails generate rolemodel_sower:install
@@ -3,4 +3,7 @@
3
3
  RolemodelSower.setup do |config|
4
4
  # Available Adapters :yaml, :csv, :tsv, :json
5
5
  # config.adapter = :yaml
6
+
7
+ # Path to the directory containing the seed data files
8
+ # config.data_path = 'db/rolemodel_sower_data'
6
9
  end
@@ -12,7 +12,7 @@ module RolemodelSower
12
12
  end
13
13
 
14
14
  def self.path(seed_name)
15
- Rails.root.join("db/rolemodel_sower_data/#{seed_name.to_s.pluralize}#{file_extension}")
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RolemodelSower
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.2'
5
5
  end
@@ -14,6 +14,9 @@ module RolemodelSower
14
14
  mattr_accessor :adapter
15
15
  @@adapter = :yaml
16
16
 
17
+ mattr_accessor :data_path
18
+ @@data_path = 'db/rolemodel_sower_data'
19
+
17
20
  def self.setup
18
21
  yield self
19
22
  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.1
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-19 00:00:00.000000000 Z
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