seedie 0.4.0 → 0.4.1

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: 7b22e6527a57385dbb0b5fc616cf632b84550a3ce8237f286a64b931670bd34a
4
- data.tar.gz: edeb838fb02090e02a9434260e08f6cb376b4b9d1e16a75e7dc3bd97c6d0a14a
3
+ metadata.gz: 0a25c63e4fcff73414ac22c60e08d8f7e2c7cd831e0480922cd3dd64bb5598b3
4
+ data.tar.gz: b824464c1d4d084856adbaec92e677ac09f1e3f983fd103ada6638df0b535d23
5
5
  SHA512:
6
- metadata.gz: 85ae796fa177098ac721addf4e4da3a10f12e26613318fb8f3fe8d126d008ec3de310115b877848fa607a91ad69e51c7c10a531322100050e76e45e89a2f2b72
7
- data.tar.gz: cb9fe8d4333e9a80f32fc33bab4e8fbe5066832121ab5c49bb3701691e8a07147115819f13ee41e58eb91d90d03a247e6bfe5f5280cc600b4c307c251b0e98fc
6
+ metadata.gz: 901e08a66477d23d1c108071f116206d4f530a46911402ca178baf66e433cda231c884fbbb667b186842c03e6d1b608bda31be44071d360cfdc28f1f46242482
7
+ data.tar.gz: ff5a02c6f6a14af3bc041fc2d39a1550d66dcca61f1491160718cb59a5fc17a07963cf5e6302bbbc89f856796d6c4a0d0a7080167b48173023cbf5454170276d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,33 @@
1
+ ## Verson 0.4.1
2
+
3
+ ### New Features
4
+
5
+ #### Added Model-specific Custom Attributes
6
+ * [GitHub PR](https://github.com/keshavbiswa/seedie/pull/47)
7
+
8
+ You can now define custom attributes for specific models in your `Seedie.configure` block:
9
+
10
+ ```ruby
11
+ Seedie.configure do |config|
12
+ # Default custom attribute for all models
13
+ config.custom_attributes[:email] = "{{Faker::Internet.unique.email}}"
14
+
15
+ # Model-specific custom attribute
16
+ config.custom_attributes[:user][:email] = "email_#{rand(10)}@example.com"
17
+ end
18
+ ```
19
+
20
+ ### Enhancements
21
+
22
+ #### Rubocop Cleanup
23
+ * [GitHub PR](https://github.com/keshavbiswa/seedie/pull/45)
24
+
25
+ #### Improved README
26
+ * [GitHub PR](https://github.com/keshavbiswa/seedie/pull/44)
27
+
28
+ #### Added Screencast
29
+ * [GitHub PR](https://github.com/keshavbiswa/seedie/pull/46)
30
+
1
31
  ## Version 0.4.0
2
32
 
3
33
  ### New Features
data/README.md CHANGED
@@ -8,6 +8,10 @@ The gem includes a Rake task for seeding models and a Rails generator for easy s
8
8
  [![Gem Version](https://badge.fury.io/rb/seedie.svg)](https://badge.fury.io/rb/seedie)
9
9
  ![Build Status](https://github.com/keshavbiswa/seedie/workflows/CI/badge.svg?branch=main)
10
10
 
11
+ ## Screencast
12
+
13
+ [![Introducing Seedie](https://img.youtube.com/vi/3W0wRrOtsTk/0.jpg)](https://www.youtube.com/watch?v=3W0wRrOtsTk)
14
+
11
15
  ## Installation
12
16
 
13
17
  Add the following line to your application's Gemfile:
@@ -54,13 +58,13 @@ $ rails generate seedie:install --blank
54
58
  This will generate a blank seedie.yml config file for you that you can now customize according to your needs.
55
59
 
56
60
  ### Excluding Models
57
- If you want to exclude certain models while generating the `seedie.yml`, use the `--exclude_models` option:
61
+ If you want to exclude certain models while generating the `seedie.yml`, use the `--excluded_models` option:
58
62
 
59
63
  ```bash
60
- $ rails generate seedie:install --exclude_models User Admin Post
64
+ $ rails generate seedie:install --excluded_models User Admin Post
61
65
  ```
62
66
 
63
- NOTE: Some models may not be excluded because of their dependencies. For example, if you have a model `Post` that belongs to a model `User`, then the `User` model will not be excluded even if you specify it in the `--exclude_models` option.
67
+ NOTE: Some models may not be excluded because of their dependencies. For example, if you have a model `Post` that belongs to a model `User`, then the `User` model will not be excluded even if you specify it in the `--excluded_models` option.
64
68
 
65
69
  You'll get a warning in your console if any models are not excluded:
66
70
 
@@ -113,7 +117,7 @@ $ rake seedie:seed
113
117
 
114
118
  This will use the configurations specified in seedie.yml to seed your models.
115
119
 
116
- The seedie.yml file has entries for each model in your application, and you can customize the configuration for each one.
120
+ The seedie.yml file has entries for each model in your application, and you can customize the configuration for each one.
117
121
 
118
122
  Here's an example of a more advanced configuration in seedie.yml:
119
123
 
@@ -133,7 +137,7 @@ models:
133
137
  title: "title {{index}}"
134
138
  category:
135
139
  values: [tech, sports, politics, entertainment]
136
- options:
140
+ options:
137
141
  pick_strategy: random # or sequential
138
142
  associations:
139
143
  has_many:
@@ -141,7 +145,7 @@ models:
141
145
  belongs_to:
142
146
  user: random # or new
143
147
  has_one:
144
- post_metadatum:
148
+ post_metadatum:
145
149
  attributes:
146
150
  seo_text: "{{Faker::Lorem.paragraph}}"
147
151
  has_and_belongs_to_many:
@@ -178,7 +182,7 @@ In this file:
178
182
 
179
183
  ## Development
180
184
 
181
- After checking out the repo, run `bin/setup` to install dependencies.
185
+ After checking out the repo, run `bin/setup` to install dependencies.
182
186
  Then, run `bundle exec rspec` to run the tests.
183
187
  By default, the tests will supress output of the seeds progress.
184
188
  Use `DEBUG_OUTPUT=true bundle exec rspec` to see the output of the seeds.
@@ -4,5 +4,19 @@ Seedie.configure do |config|
4
4
  # config.default_count = 10
5
5
 
6
6
  config.custom_attributes[:email] = "{{Faker::Internet.unique.email}}"
7
+ # Model-Specific Custom Attributes
8
+ #
9
+ # Use the prepare_custom_attributes_for method to initialize the custom_attributes hash
10
+ # for the specified models. This ensures that you can safely set model-specific custom
11
+ # attributes without encountering NoMethodError.
12
+ #
13
+ # Example:
14
+ # config.prepare_custom_attributes_for :user, :account
15
+ #
16
+ # Now you can set custom attributes for these models:
17
+ # config.custom_attributes[:user][:email] = "user@example.com"
18
+ # config.custom_attributes[:account][:name] = "{{Faker::Business.name}}"
19
+ #
7
20
  # Add more custom attributes here
21
+ #
8
22
  end
@@ -8,5 +8,23 @@ module Seedie
8
8
  @default_count = nil
9
9
  @custom_attributes = {}
10
10
  end
11
+
12
+ # Prepares the custom_attributes hash for the specified models.
13
+ #
14
+ # This method ensures that the necessary keys exist in the custom_attributes hash.
15
+ # This prevents NoMethodError when setting model-specific custom attributes.
16
+ #
17
+ # Example usage:
18
+ # config.prepare_custom_attributes_for :user, :account
19
+ #
20
+ # Then this will work:
21
+ # config.custom_attributes[:user][:name] = "Name"
22
+ # config.custom_attributes[:account][:email] = "email@example.com"
23
+ #
24
+ def prepare_custom_attributes_for(*models)
25
+ models.inject(@custom_attributes) do |hash, key|
26
+ hash[key] ||= {}
27
+ end
28
+ end
11
29
  end
12
30
  end
@@ -16,7 +16,8 @@ module Seedie
16
16
  end
17
17
 
18
18
  def build_faker_constant
19
- return @seedie_config_custom_attributes[@name.to_sym] if @seedie_config_custom_attributes.key?(@name.to_sym)
19
+ custom_attribute = fetch_custom_attribute
20
+ return custom_attribute if fetch_custom_attribute
20
21
 
21
22
  @unique_prefix = "unique." if has_validation?(:uniqueness)
22
23
 
@@ -39,6 +40,14 @@ module Seedie
39
40
 
40
41
  private
41
42
 
43
+ def fetch_custom_attribute
44
+ if @seedie_config_custom_attributes[@name.to_sym].is_a?(Hash)
45
+ return @seedie_config_custom_attributes.dig(@name.to_sym, @column.name.to_sym)
46
+ end
47
+
48
+ @seedie_config_custom_attributes[@name.to_sym]
49
+ end
50
+
42
51
  def add_faker_class_and_method(type)
43
52
  case type
44
53
  when :string, :text, :citext
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Seedie
4
- VERSION = "0.4.0"
4
+ VERSION = "0.4.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seedie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keshav Biswa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-11-10 00:00:00.000000000 Z
11
+ date: 2025-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -189,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
189
  - !ruby/object:Gem::Version
190
190
  version: '0'
191
191
  requirements: []
192
- rubygems_version: 3.4.1
192
+ rubygems_version: 3.4.10
193
193
  signing_key:
194
194
  specification_version: 4
195
195
  summary: Automate Database Seeding For ActiveRecord