rails_json_seeder 0.1.1 → 0.1.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: 6f2c58b24d9cc7bffbf180174e4f534366784e8518bb2e2e3b1d30a4413b0213
4
- data.tar.gz: 8fd0377aa419a5a56e5032d81ecfefa0112ae4185affe90c65fa3b6df7806c48
3
+ metadata.gz: 92ad673104e2356514757c6ca7b6c7e7c301a93ed17499a48ea7eacf67142270
4
+ data.tar.gz: 1500a9b9f478b034504f9eeea268744b22db60e5efa15f7b9618065b6d7dbe3a
5
5
  SHA512:
6
- metadata.gz: 0af397096de31b2cf74cbae4441808abe978152804ce7b863c71af5d9f1c01d6dff005b591e81b4b17acee6b82274454fe8f930ae30e72900076e374a37f287c
7
- data.tar.gz: 9e9a654af9924762d9b21373ea19544e6a80ccf373b03295d99e2f3539d8688bf6fafcc19653b12b7541326b0b80c52e0cfe808d3a64b73412e864c9ebfe3298
6
+ metadata.gz: 04d440f3ed93818fed9adcffebcbf1eb160e972aac6bbe93d51bf8cc9c8ade722a94b978eb54b04983074ee97de83292c01b0880128e2372c10740c78ccfd5c4
7
+ data.tar.gz: f080a0df2f5cf50030608fee152d7bc1b4003b9c41c33bd46f0533f891a8395dcf9cf6a01a80522a875e3b9c0c73865c03a485a654273ee6854fc67483434838
data/.rubocop.yml CHANGED
@@ -18,3 +18,5 @@ Metrics/MethodLength:
18
18
  Metrics/ModuleLength:
19
19
  Max: 150
20
20
 
21
+ Metrics/BlockLength:
22
+ Max: 40
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,22 @@
1
+
2
+
3
+ ### How to start development
4
+ #### clone repo
5
+ ```
6
+ $ git clone git@github.com:yamamoto7/rails_json_seeder.git
7
+ $ cd rails_json_seeder
8
+ ```
9
+
10
+ #### add or edit code
11
+ ```
12
+ ├─ lib/
13
+ ├─ rails_json_seeder.rb # entry point
14
+ └─ rails_json_seeder/
15
+ └─ seeder.rb # core functions
16
+ ```
17
+
18
+ #### try features
19
+ ```
20
+ $ cd test/dummy/
21
+ $ rails db:seed
22
+ ```
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_json_seeder (0.1.1)
4
+ rails_json_seeder (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -95,6 +95,7 @@ GEM
95
95
  marcel (1.0.2)
96
96
  method_source (1.0.0)
97
97
  mini_mime (1.1.5)
98
+ mini_portile2 (2.8.8)
98
99
  minitest (5.20.0)
99
100
  net-imap (0.4.1)
100
101
  date
@@ -106,7 +107,8 @@ GEM
106
107
  net-smtp (0.4.0)
107
108
  net-protocol
108
109
  nio4r (2.5.9)
109
- nokogiri (1.15.4-arm64-darwin)
110
+ nokogiri (1.15.4)
111
+ mini_portile2 (~> 2.8.2)
110
112
  racc (~> 1.4)
111
113
  parallel (1.23.0)
112
114
  parser (3.2.2.4)
@@ -199,6 +201,8 @@ GEM
199
201
 
200
202
  PLATFORMS
201
203
  arm64-darwin-22
204
+ arm64-darwin-23
205
+ x86_64-linux
202
206
 
203
207
  DEPENDENCIES
204
208
  factory_bot_rails
data/README.md CHANGED
@@ -1,154 +1,48 @@
1
1
  # RailsJsonSeeder
2
+ [English ver](https://github.com/yamamoto7/rails_json_seeder/blob/main/README_EN.md)
2
3
 
3
- RailsJsonSeeder is a gem to easily read JSON seed data for Rails applications and reflect it in the database.
4
+ [![Gem Version](https://badge.fury.io/rb/rails_json_seeder.svg)](https://badge.fury.io/rb/rails_json_seeder) [![Open Source Helpers badge](https://codetriage.com/yamamoto7/rails_json_seeder/badges/users.svg)](https://codetriage.com/yamamoto7/rails_json_seeder)
4
5
 
5
- ## Installation
6
+ ![rails_json_seeder](https://github.com/yamamoto7/rails_json_seeder/assets/37437497/4923637f-baf9-4e98-97e9-8d2d40539ab7)
6
7
 
7
- Install the gem and add to the application's Gemfile by executing:
8
- ```
9
- $ gem install rails_json_seeder
10
- ```
11
-
12
- ## Quickstart
13
- ### Setup
14
- First, call RailsJsonSeeder in the seed.rb file as follows:
15
- ```
16
- RailsJsonSeeder.load_seeds('db/seed_config.yml')
17
- ```
8
+ Json形式で定義されたシードデータを簡単に取り込むことができるgemです
18
9
 
19
- ### Creating a configuration file
20
- `seed_config`
10
+ ## クイックスタート
11
+ ### Install
12
+ Gemfileに本gemを追加してください。
21
13
  ```
22
- seed_file_base_path: 'db/seed_json/' # default value is db/
23
- files:
24
- 'users.json':
25
- model: User
26
- 'categories.json':
27
- model: Category
28
- 'books.json':
29
- model: Book
30
- dependencies:
31
- - class: Category
32
- 'user_books.json':
33
- model: UserBook
34
- dependencies:
35
- - class: User
36
- - class: Book
14
+ gem 'rails_json_seeder'
37
15
  ```
38
16
 
39
- ### Creating JSON files
40
- `user_books.json`
41
- ```
42
- [
43
- {
44
- "first_name": "John",
45
- "last_name": "Doe"
46
- },
47
- {
48
- "first_name": "Bob",
49
- "last_name": "Brown"
50
- }
51
- ]
52
- ```
53
- `categories.json`
54
- ```
55
- [
56
- {
57
- "label": "Science Fiction"
58
- },
59
- {
60
- "label": "History"
61
- }
62
- ]
63
- ```
64
- `books.json`
17
+ 追加後以下のコマンドを実行してください。
65
18
  ```
66
- [
67
- {
68
- "title": "The Time Traveler's Tale",
69
- "description": "An intriguing story of a man who discovers a machine that can transport him through time.",
70
- "category": {
71
- "label": "Science Fiction"
72
- }
73
- },
74
- {
75
- "title": "Stars Beyond Reach",
76
- "description": "Set in a distant future, a tale of interstellar exploration and the challenges faced by humanity in the vastness of space.",
77
- "category": {
78
- "label": "Science Fiction"
79
- }
80
- },
81
- {
82
- "title": "Rise and Fall of Empires",
83
- "description": "An exhaustive study of the world's greatest empires, their dominance, and eventual decline.",
84
- "category": {
85
- "label": "History"
86
- }
87
- }
88
- ]
89
- ```
90
- `user_books.json`
91
- ```
92
- [
93
- {
94
- "book": {
95
- "title": "The Time Traveler's Tale"
96
- },
97
- "user": {
98
- "first_name": "John",
99
- "last_name": "Doe"
100
- }
101
- },
102
- {
103
- "book": {
104
- "title": "Rise and Fall of Empires"
105
- },
106
- "user": {
107
- "first_name": "Bob",
108
- "last_name": "Brown"
109
- }
110
- }
111
- ]
19
+ $ bundle install
112
20
  ```
113
21
 
22
+ ### SeedデータでRailsJsonSeederを利用する例
114
23
 
115
- ## Contributions
116
- 🌱 Early Days of Our Project: We'd like to candidly express that RailsJsonSeeder is in its infancy. As with many open-source software (OSS) projects in their early stages, there may be areas that are not yet polished or might require further refinements.
24
+ 1. [seed.rbの例](https://github.com/yamamoto7/rails_json_seeder/blob/main/test/dummy/db/seeds.rb)
25
+ 2. [設定ファイルの例](https://github.com/yamamoto7/rails_json_seeder/blob/main/test/dummy/db/seed_config_sample_1.yml)
26
+ 3. [jsonファイルの例](https://github.com/yamamoto7/rails_json_seeder/tree/main/test/dummy/db/seed_json_sample_1)
117
27
 
118
- 🤝 Your Contribution Matters: Despite our project's budding phase, or perhaps because of it, every contribution holds significant value. Whether you're a veteran open-source contributor or a newcomer, your insights, feedback, and contributions can make a real difference.
28
+ ## 貢献
29
+ 🌱 プロジェクトの状態: 率直に申し上げますが、RailsJsonSeederはまだ初期段階にあります。初期段階にある多くのオープンソースソフトウェア (OSS) プロジェクトと同様、まだ洗練されていない部分や、さらなる改良が必要な部分があるかもしれません。
119
30
 
120
- ### How Can You Help?
121
- 1. Identifying Bugs: If you notice any bugs or inconsistencies, please open an issue. Your detailed observations can help us rectify and improve.
122
- 2. Suggesting Enhancements: Have ideas on how we can do better? Propose enhancements or new features. We're all ears!
123
- 3. Code Contributions: Directly contribute to the codebase following the previously mentioned contribution steps. If you're uncertain about something, feel free to ask.
124
- 4. Documentation & Examples: Found a typo? Think a section of our documentation could be clearer? Your feedback can make our documentation more user-friendly.
125
- 5. Spreading the Word: The more people know about our project, the better. Share our project, write about it, or even give us a shoutout.
31
+ 🤝 あなたの貢献が重要です: 私たちのプロジェクトは萌芽的な段階ですが、あるいは萌芽的だからこそ、すべての貢献は重要な価値を持ちます。ベテランのオープンソース貢献者であろうと、新参者であろうと、あなたの洞察力、フィードバック、そして貢献は、真の変化をもたらすことができます。
126
32
 
127
- ### An Invitation to All:
128
- This is a space of collaboration, learning, and growth. We're committed to fostering a welcoming and inclusive environment for everyone. If you ever have questions, feedback, or suggestions, please don't hesitate to reach out.
33
+ ### どのように貢献できますか?
34
+ 1. バグの特定: バグや矛盾にお気づきの場合は、issue を開いてください。あなたの詳細な観察は、私たちが修正し、改善するのに役立ちます。
35
+ 2. 機能強化の提案: より良いものを作るためのアイデアをお持ちですか?機能強化や新機能をご提案ください。お待ちしております!
36
+ 3. コードへの貢献: 前述の貢献ステップに従って、コードベースに直接貢献してください。不明な点があれば、遠慮なく質問してください。
37
+ 4. ドキュメントとサンプル: タイプミスを見つけましたか?私たちのドキュメントのセクションがより明確になると思いますか?あなたのフィードバックやPull Requestは、私たちのドキュメントをよりユーザーフレンドリーにすることができます。
38
+ 5. 初心者の方へ: PRの送り方がわからないですか?実装の相談がしたいですか?issueにて気軽にご質問ください。(※本OSSは日本語に対応しています)
129
39
 
130
- Together, let's make RailsJsonSeeder a valuable tool for the Rails community!
40
+ 準備ができたら、こちらから開発手順をご確認ください。
131
41
 
132
- ### How to start development
133
- #### clone repo
134
- ```
135
- $ git clone git@github.com:yamamoto7/rails_json_seeder.git
136
- $ cd rails_json_seeder
137
- ```
42
+ ### すべての人への招待状:
43
+ ここはコラボレーション、学習、成長の場です。私たちはすべての人を歓迎し、包括的な環境を育むことを約束します。質問、フィードバック、提案があれば、遠慮なく声をかけてください。
138
44
 
139
- #### add or edit code
140
- ```
141
- ├─ lib/
142
- ├─ rails_json_seeder.rb # entry point
143
- └─ rails_json_seeder/
144
- └─ seeder.rb # core functions
145
- ```
146
-
147
- #### try features
148
- ```
149
- $ cd test/dummy/
150
- $ rails db:seed
151
- ```
45
+ 一緒にRailsJsonSeederをRailsコミュニティにとって価値あるツールにしていきましょう!
152
46
 
153
47
  ## License
154
48
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/README_EN.md ADDED
@@ -0,0 +1,47 @@
1
+ # RailsJsonSeeder
2
+ [![Gem Version](https://badge.fury.io/rb/rails_json_seeder.svg)](https://badge.fury.io/rb/rails_json_seeder) [![Open Source Helpers badge](https://codetriage.com/yamamoto7/rails_json_seeder/badges/users.svg)](https://codetriage.com/yamamoto7/rails_json_seeder)
3
+
4
+ ![rails_json_seeder](https://github.com/yamamoto7/rails_json_seeder/assets/37437497/4923637f-baf9-4e98-97e9-8d2d40539ab7)
5
+
6
+ RailsJsonSeeder is a gem to easily read JSON seed data for Rails applications and reflect it in the database.
7
+
8
+ ## Installation
9
+ Add this gem to your Gemfile.
10
+
11
+ ```
12
+ gem 'rails_json_seeder'
13
+ ```
14
+
15
+ After adding this gem, please execute the following commands.
16
+ ```
17
+ $ bundle install
18
+ ```
19
+
20
+ ### Example of using RailsJsonSeeder with Seed data
21
+
22
+ 1. [Example of seed.rb](https://github.com/yamamoto7/rails_json_seeder/blob/main/test/dummy/db/seeds.rb)
23
+ 2. [Example of configuration file](https://github.com/yamamoto7/rails_json_seeder/blob/main/test/dummy/db/seed_config_sample_1.yml)
24
+ 3. [Example of json file](https://github.com/yamamoto7/rails_json_seeder/tree/main/test/dummy/db/seed_json_sample_1)
25
+
26
+ ## Contributions
27
+ 🌱 Early Days of Our Project: We'd like to candidly express that RailsJsonSeeder is in its infancy. As with many open-source software (OSS) projects in their early stages, there may be areas that are not yet polished or might require further refinements.
28
+
29
+ 🤝 Your Contribution Matters: Despite our project's budding phase, or perhaps because of it, every contribution holds significant value. Whether you're a veteran open-source contributor or a newcomer, your insights, feedback, and contributions can make a real difference.
30
+
31
+ ### How Can You Help?
32
+ 1. Identifying Bugs: If you notice any bugs or inconsistencies, please open an issue. Your detailed observations can help us rectify and improve.
33
+ 2. Suggesting Enhancements: Have ideas on how we can do better? Propose enhancements or new features. We're all ears!
34
+ 3. Code Contributions: Directly contribute to the codebase following the previously mentioned contribution steps. If you're uncertain about something, feel free to ask.
35
+ 4. Documentation & Examples: Found a typo? Think a section of our documentation could be clearer? Your feedback can make our documentation more user-friendly.
36
+ 5. Newbies: Not sure how to send a PR? Want to discuss implementation? Please feel free to ask questions on the [issue](https://github.com/yamamoto7/rails_json_seeder/issues).
37
+
38
+ When you are ready, please click [here](https://github.com/yamamoto7/rails_json_seeder/blob/main/CONTRIBUTING.md) to review the development process.
39
+
40
+ ### An Invitation to All:
41
+ This is a space of collaboration, learning, and growth. We're committed to fostering a welcoming and inclusive environment for everyone. If you ever have questions, feedback, or suggestions, please don't hesitate to reach out.
42
+
43
+ Together, let's make RailsJsonSeeder a valuable tool for the Rails community!
44
+
45
+ ## License
46
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
47
+
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_record'
2
4
  require 'rails'
3
5
  require 'active_support/core_ext/hash/keys'
@@ -36,7 +38,7 @@ module RailsJsonSeeder
36
38
  end
37
39
  end
38
40
 
39
- def process_file(path, item)
41
+ def process_file(path, item) # rubocop:disable Metrics/AbcSize
40
42
  klass = resolve_constant(item[:model])
41
43
 
42
44
  dependencies = item[:dependencies] || {}
@@ -73,6 +75,9 @@ module RailsJsonSeeder
73
75
  dependency_class = resolve_constant(dependency[:class])
74
76
  foreign_key = dependency[:id] || "#{dependency_class.name.underscore}_id"
75
77
  original_field_name = dependency[:alias] || dependency_class.name.underscore
78
+
79
+ next unless record[original_field_name]
80
+
76
81
  dependent_record = dependency_class.find_by!(record[original_field_name])
77
82
  record[foreign_key] = dependent_record.id
78
83
  record.delete(original_field_name)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsJsonSeeder
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_json_seeder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - kenta.yamamoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-13 00:00:00.000000000 Z
11
+ date: 2024-12-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: RailsJsonSeeder provides an intuitive way to seed Rails applications
14
14
  using JSON formatted seed files. With support for defining model dependencies, this
@@ -24,10 +24,12 @@ files:
24
24
  - ".rubocop.yml"
25
25
  - CHANGELOG.md
26
26
  - CODE_OF_CONDUCT.md
27
+ - CONTRIBUTING.md
27
28
  - Gemfile
28
29
  - Gemfile.lock
29
30
  - LICENSE.txt
30
31
  - README.md
32
+ - README_EN.md
31
33
  - Rakefile
32
34
  - lib/rails_json_seeder.rb
33
35
  - lib/rails_json_seeder/seeder.rb
@@ -55,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
57
  - !ruby/object:Gem::Version
56
58
  version: '0'
57
59
  requirements: []
58
- rubygems_version: 3.4.10
60
+ rubygems_version: 3.5.11
59
61
  signing_key:
60
62
  specification_version: 4
61
63
  summary: A gem for easy seeding of Rails projects from JSON files.