rbcsv 0.1.6 → 0.1.8
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/.rust-analyzer.json +8 -0
- data/CHANGELOG.md +44 -0
- data/Cargo.lock +123 -45
- data/DEVELOPMENT.md +467 -129
- data/README.md +66 -5
- data/ext/rbcsv/Cargo.toml +6 -2
- data/ext/rbcsv/src/error.rs +101 -0
- data/ext/rbcsv/src/lib.rs +14 -143
- data/ext/rbcsv/src/parser.rs +306 -0
- data/ext/rbcsv/src/ruby_api.rs +111 -0
- data/lib/rbcsv/version.rb +1 -1
- data/test_write_functionality.rb +225 -0
- metadata +6 -1
data/DEVELOPMENT.md
CHANGED
|
@@ -1,24 +1,32 @@
|
|
|
1
|
-
# 開発ガイド
|
|
1
|
+
# RbCsv 開発ガイド
|
|
2
2
|
|
|
3
|
-
このドキュメントでは、rbcsv
|
|
3
|
+
このドキュメントでは、rbcsvの開発環境のセットアップ、ビルド方法、テスト手順、リリース手順について詳しく説明します。
|
|
4
4
|
|
|
5
5
|
## 必要な環境
|
|
6
6
|
|
|
7
|
-
- Ruby 3.0
|
|
8
|
-
- Rust
|
|
9
|
-
- Bundler gem
|
|
10
|
-
- Git
|
|
7
|
+
- **Ruby**: 3.2.0以降(gemspec要件)
|
|
8
|
+
- **Rust**: 最新の安定版を推奨(MSRV: 1.75+)
|
|
9
|
+
- **Bundler**: gem管理
|
|
10
|
+
- **Git**: バージョン管理
|
|
11
|
+
- **RubyGems**: 3.3.11以降
|
|
12
|
+
|
|
13
|
+
### システム要件
|
|
14
|
+
|
|
15
|
+
- **macOS**: Apple Silicon (arm64) / Intel (x86_64)
|
|
16
|
+
- **Linux**: x86_64 / aarch64
|
|
17
|
+
- **Windows**: x86_64(実験的サポート)
|
|
18
|
+
|
|
11
19
|
|
|
12
20
|
## 開発環境のセットアップ
|
|
13
21
|
|
|
14
22
|
### 1. リポジトリのクローン
|
|
15
23
|
|
|
16
24
|
```bash
|
|
17
|
-
git clone
|
|
18
|
-
cd
|
|
25
|
+
git clone https://github.com/fs0414/rbcsv.git
|
|
26
|
+
cd rbcsv
|
|
19
27
|
```
|
|
20
28
|
|
|
21
|
-
### 2. 依存関係のインストール
|
|
29
|
+
### 2. Ruby依存関係のインストール
|
|
22
30
|
|
|
23
31
|
```bash
|
|
24
32
|
bundle install
|
|
@@ -27,221 +35,551 @@ bundle install
|
|
|
27
35
|
### 3. ネイティブ拡張のビルド
|
|
28
36
|
|
|
29
37
|
```bash
|
|
38
|
+
# 推奨方法(rb_sys使用)
|
|
30
39
|
rake compile
|
|
40
|
+
|
|
41
|
+
# 代替方法(開発時)
|
|
42
|
+
bundle exec rake compile
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 4. 動作確認
|
|
46
|
+
|
|
47
|
+
#### CSV パース機能
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
# 基本的なパース
|
|
51
|
+
ruby -I lib -e "require 'rbcsv'; p RbCsv.parse('a,b\n1,2')"
|
|
52
|
+
# 期待される出力: [["a", "b"], ["1", "2"]]
|
|
53
|
+
|
|
54
|
+
# trim機能付きパース
|
|
55
|
+
ruby -I lib -e "require 'rbcsv'; p RbCsv.parse!(' a , b \n 1 , 2 ')"
|
|
56
|
+
# 期待される出力: [["a", "b"], ["1", "2"]]
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
#### CSV ファイル読み込み機能
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
# CSVファイル読み込み
|
|
63
|
+
ruby -I lib -e "require 'rbcsv'; p RbCsv.read('spec/fixtures/test.csv')"
|
|
64
|
+
# 期待される出力: [["name", "age", "city"], ["Alice", "25", "Tokyo"], ...]
|
|
65
|
+
|
|
66
|
+
# trim機能付きファイル読み込み
|
|
67
|
+
ruby -I lib -e "require 'rbcsv'; p RbCsv.read!('spec/fixtures/test_with_spaces.csv')"
|
|
68
|
+
# 期待される出力: [["name", "age", "city"], ["Alice", "25", "Tokyo"], ...]
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
#### CSV ファイル書き込み機能
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
# 基本的なファイル書き込み
|
|
75
|
+
ruby -I lib -e "
|
|
76
|
+
require 'rbcsv'
|
|
77
|
+
data = [['name', 'age', 'city'], ['Alice', '25', 'Tokyo'], ['Bob', '30', 'Osaka']]
|
|
78
|
+
RbCsv.write('/tmp/test_output.csv', data)
|
|
79
|
+
puts 'File written successfully!'
|
|
80
|
+
puts File.read('/tmp/test_output.csv')
|
|
81
|
+
"
|
|
82
|
+
# 期待される出力:
|
|
83
|
+
# File written successfully!
|
|
84
|
+
# name,age,city
|
|
85
|
+
# Alice,25,Tokyo
|
|
86
|
+
# Bob,30,Osaka
|
|
87
|
+
|
|
88
|
+
# 書き込み→読み込みの往復テスト
|
|
89
|
+
ruby -I lib -e "
|
|
90
|
+
require 'rbcsv'
|
|
91
|
+
data = [['product', 'price'], ['Apple', '100'], ['Orange', '80']]
|
|
92
|
+
RbCsv.write('/tmp/roundtrip.csv', data)
|
|
93
|
+
result = RbCsv.read('/tmp/roundtrip.csv')
|
|
94
|
+
puts 'Original data:'
|
|
95
|
+
p data
|
|
96
|
+
puts 'Read back data:'
|
|
97
|
+
p result
|
|
98
|
+
puts 'Match: #{data == result}'
|
|
99
|
+
"
|
|
100
|
+
# 期待される出力: Match: true
|
|
101
|
+
|
|
102
|
+
# エラーハンドリングテスト(空データ)
|
|
103
|
+
ruby -I lib -e "
|
|
104
|
+
require 'rbcsv'
|
|
105
|
+
begin
|
|
106
|
+
RbCsv.write('/tmp/empty.csv', [])
|
|
107
|
+
rescue => e
|
|
108
|
+
puts 'Error caught: #{e.message}'
|
|
109
|
+
end
|
|
110
|
+
"
|
|
111
|
+
# 期待される出力: Error caught: Invalid Data Error: CSV data is empty
|
|
112
|
+
|
|
113
|
+
# エラーハンドリングテスト(フィールド数不一致)
|
|
114
|
+
ruby -I lib -e "
|
|
115
|
+
require 'rbcsv'
|
|
116
|
+
begin
|
|
117
|
+
data = [['name', 'age'], ['Alice', '25', 'Tokyo']]
|
|
118
|
+
RbCsv.write('/tmp/mismatch.csv', data)
|
|
119
|
+
rescue => e
|
|
120
|
+
puts 'Error caught: #{e.message}'
|
|
121
|
+
end
|
|
122
|
+
"
|
|
123
|
+
# 期待される出力: Error caught: Invalid Data Error: Field count mismatch at line 2: expected 2 fields, got 3 fields
|
|
124
|
+
|
|
125
|
+
# ファイル上書きテスト
|
|
126
|
+
ruby -I lib -e "
|
|
127
|
+
require 'rbcsv'
|
|
128
|
+
# 最初のデータを書き込み
|
|
129
|
+
RbCsv.write('/tmp/overwrite_test.csv', [['old'], ['data']])
|
|
130
|
+
puts 'First write:'
|
|
131
|
+
puts File.read('/tmp/overwrite_test.csv')
|
|
132
|
+
|
|
133
|
+
# 新しいデータで上書き
|
|
134
|
+
RbCsv.write('/tmp/overwrite_test.csv', [['new', 'data'], ['updated', 'content']])
|
|
135
|
+
puts 'After overwrite:'
|
|
136
|
+
puts File.read('/tmp/overwrite_test.csv')
|
|
137
|
+
"
|
|
138
|
+
# 期待される出力: 最初にold,dataが出力され、その後new,data形式に変わる
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## ビルドプロセス
|
|
142
|
+
|
|
143
|
+
### 自動ビルド(推奨)
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
# 全体ビルド(コンパイル、テスト、リント)
|
|
147
|
+
rake
|
|
148
|
+
|
|
149
|
+
# 拡張のみコンパイル
|
|
150
|
+
rake compile
|
|
151
|
+
|
|
152
|
+
# クリーンビルド
|
|
153
|
+
rake clean
|
|
154
|
+
rake compile
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### 手動ビルド手順
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
# 1. 前回のビルドをクリーン
|
|
161
|
+
rm -rf lib/rbcsv/rbcsv.bundle tmp/ target/
|
|
162
|
+
|
|
163
|
+
# 2. Rust拡張のコンパイル
|
|
164
|
+
cd ext/rbcsv
|
|
165
|
+
cargo build --release
|
|
166
|
+
cd ../..
|
|
167
|
+
|
|
168
|
+
# 3. バンドルファイルのコピー(macOSの場合)
|
|
169
|
+
cp target/release/librbcsv.dylib lib/rbcsv/rbcsv.bundle
|
|
170
|
+
|
|
171
|
+
# Linuxの場合
|
|
172
|
+
# cp target/release/librbcsv.so lib/rbcsv/rbcsv.bundle
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### ビルドのトラブルシューティング
|
|
176
|
+
|
|
177
|
+
#### ABIバージョンの不一致
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
# エラー例: "incompatible ABI version"
|
|
181
|
+
rm -rf lib/rbcsv/rbcsv.bundle tmp/ target/
|
|
182
|
+
bundle exec rake compile
|
|
31
183
|
```
|
|
32
184
|
|
|
33
|
-
|
|
185
|
+
#### Rust/Cargoの問題
|
|
34
186
|
|
|
35
|
-
#### Rubyテスト
|
|
36
187
|
```bash
|
|
188
|
+
# Rust依存関係の更新
|
|
189
|
+
cd ext/rbcsv
|
|
190
|
+
cargo update
|
|
191
|
+
cargo clean
|
|
192
|
+
cargo build --release
|
|
193
|
+
cd ../..
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
#### Magnus APIエラー
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
# 最新のMagnus 0.8.1では、ReprValueトレイトの明示的インポートが必要
|
|
200
|
+
# ruby_api.rs で以下が含まれていることを確認:
|
|
201
|
+
use magnus::{value::ReprValue};
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## テスト手順
|
|
205
|
+
|
|
206
|
+
### Ruby統合テスト
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
# 全テスト実行
|
|
37
210
|
bundle exec rspec
|
|
211
|
+
|
|
212
|
+
# 特定のテストファイル
|
|
213
|
+
bundle exec rspec spec/rbcsv_spec.rb
|
|
214
|
+
|
|
215
|
+
# 詳細出力
|
|
216
|
+
bundle exec rspec --format documentation
|
|
38
217
|
```
|
|
39
218
|
|
|
40
|
-
|
|
219
|
+
### Rustユニットテスト
|
|
220
|
+
|
|
41
221
|
```bash
|
|
222
|
+
# 全Rustテスト
|
|
42
223
|
cd ext/rbcsv
|
|
43
224
|
cargo test
|
|
225
|
+
|
|
226
|
+
# 詳細出力
|
|
227
|
+
cargo test -- --nocapture
|
|
228
|
+
|
|
229
|
+
# 特定のテスト
|
|
230
|
+
cargo test test_parse_basic
|
|
44
231
|
cd ../..
|
|
45
232
|
```
|
|
46
233
|
|
|
47
|
-
###
|
|
234
|
+
### パフォーマンステスト
|
|
48
235
|
|
|
49
236
|
```bash
|
|
50
|
-
|
|
237
|
+
# ベンチマーク実行
|
|
238
|
+
ruby benchmark.rb
|
|
239
|
+
|
|
240
|
+
# カスタムテストファイルでのテスト
|
|
241
|
+
ruby test.rb
|
|
51
242
|
```
|
|
52
243
|
|
|
53
|
-
|
|
244
|
+
### コードスタイルチェック
|
|
54
245
|
|
|
55
|
-
|
|
246
|
+
```bash
|
|
247
|
+
# Rubyコード(RuboCop)
|
|
248
|
+
bundle exec rubocop
|
|
56
249
|
|
|
250
|
+
# Rustコード
|
|
251
|
+
cd ext/rbcsv
|
|
252
|
+
cargo fmt --check
|
|
253
|
+
cargo clippy -- -D warnings
|
|
254
|
+
cd ../..
|
|
57
255
|
```
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
256
|
+
|
|
257
|
+
## API設計
|
|
258
|
+
|
|
259
|
+
### 現在のAPI(v0.1.7+)
|
|
260
|
+
|
|
261
|
+
```ruby
|
|
262
|
+
# 関数ベースAPI(`!`サフィックスでtrim機能分離)
|
|
263
|
+
RbCsv.parse(csv_string) # 通常のパース
|
|
264
|
+
RbCsv.parse!(csv_string) # trim機能付きパース
|
|
265
|
+
RbCsv.read(file_path) # 通常のファイル読み込み
|
|
266
|
+
RbCsv.read!(file_path) # trim機能付きファイル読み込み
|
|
267
|
+
RbCsv.write(file_path, data) # CSVファイル書き込み
|
|
268
|
+
|
|
269
|
+
# データ形式
|
|
270
|
+
data = [
|
|
271
|
+
["header1", "header2", "header3"], # ヘッダー行
|
|
272
|
+
["value1", "value2", "value3"], # データ行
|
|
273
|
+
# ...
|
|
274
|
+
]
|
|
74
275
|
```
|
|
75
276
|
|
|
76
|
-
|
|
277
|
+
### API進化の履歴
|
|
77
278
|
|
|
78
|
-
|
|
279
|
+
#### v0.1.6以前(オプションベース)
|
|
280
|
+
```ruby
|
|
281
|
+
RbCsv.parse(csv_string, {trim: true})
|
|
282
|
+
RbCsv.read(file_path, {trim: false})
|
|
283
|
+
```
|
|
79
284
|
|
|
80
|
-
|
|
285
|
+
#### v0.1.7+(関数ベース)
|
|
286
|
+
```ruby
|
|
287
|
+
RbCsv.parse!(csv_string) # trim版
|
|
288
|
+
RbCsv.write(file_path, data) # 新機能
|
|
289
|
+
```
|
|
81
290
|
|
|
82
|
-
|
|
83
|
-
```bash
|
|
84
|
-
rm -rf lib/rbcsv/rbcsv.bundle tmp/
|
|
85
|
-
```
|
|
291
|
+
### 実装アーキテクチャ
|
|
86
292
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
293
|
+
1. **parser.rs**: CSV解析・書き込みコア機能、エラーハンドリング
|
|
294
|
+
2. **ruby_api.rs**: Ruby API関数、Magnus バインディング
|
|
295
|
+
3. **lib.rs**: Magnus初期化と関数登録
|
|
296
|
+
4. **error.rs**: 包括的なエラーハンドリングとRuby例外変換
|
|
91
297
|
|
|
92
|
-
|
|
93
|
-
```bash
|
|
94
|
-
cd ext/rbcsv
|
|
95
|
-
cargo build --release
|
|
96
|
-
cp ../../target/release/librbcsv.dylib ../../lib/rbcsv/rbcsv.bundle
|
|
97
|
-
cd ../..
|
|
98
|
-
```
|
|
298
|
+
### 開発時の重要な注意点
|
|
99
299
|
|
|
100
|
-
|
|
300
|
+
#### Ruby拡張ライブラリの特殊性
|
|
101
301
|
|
|
102
|
-
|
|
103
|
-
|
|
302
|
+
```bash
|
|
303
|
+
# ❌ 避けるべき: cargo buildは直接使用しない
|
|
304
|
+
# cargo build は通常のRustライブラリ用で、Ruby拡張では適切にリンクされない
|
|
305
|
+
|
|
306
|
+
# ✅ 推奨される開発フロー:
|
|
307
|
+
cd ext/rbcsv
|
|
308
|
+
cargo check # 構文チェック(リンクなし)
|
|
309
|
+
cargo test # Rust単体テスト
|
|
310
|
+
cd ../..
|
|
311
|
+
bundle exec rake compile # Ruby拡張ビルド
|
|
312
|
+
bundle exec rspec # Ruby統合テスト
|
|
313
|
+
```
|
|
104
314
|
|
|
105
|
-
|
|
106
|
-
2. クリーンして再ビルド:
|
|
107
|
-
```bash
|
|
108
|
-
rm -rf lib/rbcsv/rbcsv.bundle tmp/
|
|
109
|
-
rake compile
|
|
110
|
-
```
|
|
315
|
+
#### ビルドコマンドの使い分け
|
|
111
316
|
|
|
112
|
-
|
|
113
|
-
|
|
317
|
+
| コマンド | 用途 | 場所 | 備考 |
|
|
318
|
+
|---------|------|------|------|
|
|
319
|
+
| `cargo check` | 構文・型チェック | ext/rbcsv | 高速、リンクなし |
|
|
320
|
+
| `cargo test` | Rust単体テスト | ext/rbcsv | Rubyシンボル不要 |
|
|
321
|
+
| `cargo build` | **使用不可** | - | リンクエラーが発生 |
|
|
322
|
+
| `bundle exec rake compile` | Ruby拡張ビルド | プロジェクトルート | 本番用ビルド |
|
|
323
|
+
| `bundle exec rspec` | 統合テスト | プロジェクトルート | 完全な機能テスト |
|
|
114
324
|
|
|
115
325
|
## リリース手順
|
|
116
326
|
|
|
117
|
-
### 1.
|
|
327
|
+
### 1. 準備フェーズ
|
|
328
|
+
|
|
329
|
+
```bash
|
|
330
|
+
# 開発状況の確認
|
|
331
|
+
git status
|
|
332
|
+
git log --oneline -10
|
|
333
|
+
|
|
334
|
+
# 全テストの実行
|
|
335
|
+
rake clean
|
|
336
|
+
rake
|
|
337
|
+
|
|
338
|
+
# コードスタイルチェック
|
|
339
|
+
bundle exec rubocop
|
|
340
|
+
cd ext/rbcsv && cargo clippy && cd ../..
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
### 2. バージョン更新
|
|
344
|
+
|
|
345
|
+
```bash
|
|
346
|
+
# lib/rbcsv/version.rb を編集
|
|
347
|
+
vim lib/rbcsv/version.rb
|
|
348
|
+
```
|
|
118
349
|
|
|
119
|
-
`lib/rbcsv/version.rb`を編集:
|
|
120
350
|
```ruby
|
|
121
351
|
module RbCsv
|
|
122
|
-
VERSION = "x.y.z" #
|
|
352
|
+
VERSION = "x.y.z" # セマンティックバージョニング
|
|
123
353
|
end
|
|
124
354
|
```
|
|
125
355
|
|
|
126
|
-
###
|
|
356
|
+
### 3. CHANGELOG.md の更新
|
|
127
357
|
|
|
128
|
-
リリース用の新しいセクションを追加:
|
|
129
358
|
```markdown
|
|
130
359
|
## [x.y.z] - YYYY-MM-DD
|
|
131
360
|
|
|
132
|
-
|
|
133
|
-
-
|
|
134
|
-
|
|
135
|
-
|
|
361
|
+
### 追加
|
|
362
|
+
- 新機能の説明
|
|
363
|
+
|
|
364
|
+
### 変更
|
|
365
|
+
- 既存機能の変更点
|
|
366
|
+
|
|
367
|
+
### 修正
|
|
368
|
+
- バグ修正の説明
|
|
369
|
+
|
|
370
|
+
### 削除
|
|
371
|
+
- 削除された機能(非互換性のある変更)
|
|
372
|
+
|
|
373
|
+
### セキュリティ
|
|
374
|
+
- セキュリティ関連の修正
|
|
136
375
|
```
|
|
137
376
|
|
|
138
|
-
###
|
|
377
|
+
### 4. ビルドとテスト
|
|
139
378
|
|
|
140
379
|
```bash
|
|
141
|
-
#
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
# 拡張の再ビルド
|
|
380
|
+
# フルクリーンビルド
|
|
381
|
+
rake clean
|
|
382
|
+
bundle install
|
|
145
383
|
rake compile
|
|
146
384
|
|
|
147
|
-
#
|
|
148
|
-
|
|
385
|
+
# 統合テスト
|
|
386
|
+
rake spec
|
|
149
387
|
|
|
150
|
-
#
|
|
151
|
-
|
|
388
|
+
# 動作確認
|
|
389
|
+
ruby -I lib -e "require 'rbcsv'; puts RbCsv::VERSION"
|
|
390
|
+
ruby -I lib -e "require 'rbcsv'; p RbCsv.parse('a,b\n1,2', {})"
|
|
152
391
|
```
|
|
153
392
|
|
|
154
|
-
###
|
|
393
|
+
### 5. Gemビルド
|
|
155
394
|
|
|
156
395
|
```bash
|
|
396
|
+
# Gemファイル生成
|
|
157
397
|
gem build rbcsv.gemspec
|
|
158
|
-
```
|
|
159
398
|
|
|
160
|
-
|
|
399
|
+
# 生成確認
|
|
400
|
+
ls -la rbcsv-*.gem
|
|
401
|
+
```
|
|
161
402
|
|
|
162
|
-
###
|
|
403
|
+
### 6. 変更のコミット
|
|
163
404
|
|
|
164
405
|
```bash
|
|
165
406
|
git add -A
|
|
166
|
-
git commit -m "Release
|
|
407
|
+
git commit -m "Release v${VERSION}
|
|
167
408
|
|
|
168
|
-
|
|
169
|
-
-
|
|
409
|
+
主な変更:
|
|
410
|
+
- 変更点1の説明
|
|
411
|
+
- 変更点2の説明
|
|
412
|
+
- バグ修正やパフォーマンス改善"
|
|
170
413
|
```
|
|
171
414
|
|
|
172
|
-
###
|
|
415
|
+
### 7. タグ作成とプッシュ
|
|
173
416
|
|
|
174
417
|
```bash
|
|
175
|
-
|
|
418
|
+
VERSION=$(ruby -I lib -e "require 'rbcsv/version'; puts RbCsv::VERSION")
|
|
419
|
+
git tag "v${VERSION}"
|
|
420
|
+
git push origin main
|
|
421
|
+
git push origin "v${VERSION}"
|
|
176
422
|
```
|
|
177
423
|
|
|
178
|
-
###
|
|
424
|
+
### 8. Gem公開(オプション)
|
|
179
425
|
|
|
180
426
|
```bash
|
|
181
|
-
|
|
182
|
-
|
|
427
|
+
# RubyGems.orgへの公開
|
|
428
|
+
gem push rbcsv-${VERSION}.gem
|
|
429
|
+
|
|
430
|
+
# 公開確認
|
|
431
|
+
gem list rbcsv --remote
|
|
183
432
|
```
|
|
184
433
|
|
|
185
|
-
|
|
434
|
+
## 開発のベストプラクティス
|
|
435
|
+
|
|
436
|
+
### コードスタイル
|
|
186
437
|
|
|
187
|
-
|
|
438
|
+
#### Ruby
|
|
439
|
+
- 標準的なRuby Style Guideに従う
|
|
440
|
+
- RuboCop設定を使用(`.rubocop.yml`)
|
|
441
|
+
- frozen_string_literalを有効化
|
|
188
442
|
|
|
443
|
+
#### Rust
|
|
189
444
|
```bash
|
|
190
|
-
|
|
445
|
+
# フォーマット
|
|
446
|
+
cargo fmt
|
|
447
|
+
|
|
448
|
+
# リント
|
|
449
|
+
cargo clippy -- -D warnings
|
|
450
|
+
|
|
451
|
+
# ドキュメント生成
|
|
452
|
+
cargo doc --open
|
|
191
453
|
```
|
|
192
454
|
|
|
193
|
-
|
|
455
|
+
### テスト戦略
|
|
194
456
|
|
|
195
|
-
|
|
457
|
+
1. **単体テスト**: 各Rustモジュールに対するcargo test
|
|
458
|
+
2. **統合テスト**: Ruby APIレベルでのRSpecテスト
|
|
459
|
+
3. **パフォーマンステスト**: 大きなCSVファイルでのベンチマーク
|
|
460
|
+
4. **エッジケーステスト**: 不正なCSV、空ファイル、エンコーディング問題
|
|
196
461
|
|
|
197
|
-
###
|
|
462
|
+
### デバッグ
|
|
198
463
|
|
|
199
|
-
|
|
200
|
-
- Rustコードのフォーマットには`cargo fmt`を使用
|
|
201
|
-
- 適切なRubyリンティングツールを使用
|
|
464
|
+
#### Rust側のデバッグ
|
|
202
465
|
|
|
203
|
-
|
|
466
|
+
```rust
|
|
467
|
+
// 開発ビルドでのみ有効
|
|
468
|
+
#[cfg(debug_assertions)]
|
|
469
|
+
eprintln!("Debug: {:?}", variable);
|
|
470
|
+
|
|
471
|
+
// ログ出力(log crateを使用)
|
|
472
|
+
log::debug!("Debug information: {:?}", data);
|
|
473
|
+
```
|
|
204
474
|
|
|
205
|
-
|
|
206
|
-
- Rustユニットテストを`ext/rbcsv/src/lib.rs`に追加
|
|
207
|
-
- コミット前にすべてのテストが通ることを確認
|
|
475
|
+
#### Ruby側のデバッグ
|
|
208
476
|
|
|
209
|
-
|
|
477
|
+
```ruby
|
|
478
|
+
# 詳細エラー情報
|
|
479
|
+
begin
|
|
480
|
+
RbCsv.parse(invalid_csv, {})
|
|
481
|
+
rescue => e
|
|
482
|
+
puts "Error: #{e.class} - #{e.message}"
|
|
483
|
+
puts e.backtrace
|
|
484
|
+
end
|
|
485
|
+
```
|
|
210
486
|
|
|
211
|
-
|
|
487
|
+
## よくある問題と解決策
|
|
212
488
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
489
|
+
### ビルド関連
|
|
490
|
+
|
|
491
|
+
**問題**: "incompatible ABI version"
|
|
492
|
+
```bash
|
|
493
|
+
# 解決策: クリーンして同じRubyバージョンで再ビルド
|
|
494
|
+
rm -rf lib/rbcsv/rbcsv.bundle tmp/
|
|
495
|
+
bundle exec rake compile
|
|
216
496
|
```
|
|
217
497
|
|
|
218
|
-
|
|
498
|
+
**問題**: Rustコンパイルエラー
|
|
499
|
+
```bash
|
|
500
|
+
# 解決策: Rust依存関係の更新
|
|
501
|
+
cd ext/rbcsv
|
|
502
|
+
cargo update
|
|
503
|
+
cargo clean
|
|
504
|
+
cargo build --release
|
|
505
|
+
cd ../..
|
|
506
|
+
```
|
|
507
|
+
|
|
508
|
+
### 実行時問題
|
|
509
|
+
|
|
510
|
+
**問題**: 空配列が返される
|
|
511
|
+
- **原因**: CSVリーダーの`has_headers`設定
|
|
512
|
+
- **解決策**: 最新バージョン(v0.1.4+)を使用
|
|
219
513
|
|
|
220
|
-
|
|
514
|
+
**問題**: 日本語CSV文字化け
|
|
515
|
+
- **原因**: エンコーディング問題
|
|
516
|
+
- **解決策**: UTF-8での保存を確認、またはエンコーディング変換
|
|
221
517
|
|
|
222
|
-
###
|
|
518
|
+
### パフォーマンス問題
|
|
223
519
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
3. 再ビルドを試す: `rake compile`
|
|
520
|
+
**問題**: 大きなファイルでメモリ不足
|
|
521
|
+
- **解決策**: ストリーミング処理の実装を検討(将来の機能)
|
|
227
522
|
|
|
228
|
-
|
|
523
|
+
**問題**: 予想より遅い処理速度
|
|
524
|
+
- **チェック項目**:
|
|
525
|
+
- ファイルI/O vs メモリ処理
|
|
526
|
+
- trimオプションの使用
|
|
527
|
+
- デバッグビルド vs リリースビルド
|
|
229
528
|
|
|
230
|
-
|
|
529
|
+
## コントリビューションガイドライン
|
|
231
530
|
|
|
232
|
-
###
|
|
531
|
+
### 開発フロー
|
|
233
532
|
|
|
234
|
-
1.
|
|
235
|
-
2.
|
|
236
|
-
3.
|
|
533
|
+
1. **Issue作成**: バグ報告や機能要求
|
|
534
|
+
2. **フォーク**: 個人リポジトリへのフォーク
|
|
535
|
+
3. **ブランチ作成**: `feature/new-feature` または `fix/bug-name`
|
|
536
|
+
4. **開発**: コードの実装とテスト追加
|
|
537
|
+
5. **テスト**: 全テストの実行と確認
|
|
538
|
+
6. **プルリクエスト**: 説明と変更内容の詳細
|
|
237
539
|
|
|
238
|
-
|
|
540
|
+
### コミットメッセージ
|
|
239
541
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
542
|
+
```
|
|
543
|
+
[種類] 簡潔な説明(50文字以内)
|
|
544
|
+
|
|
545
|
+
詳細な説明(必要に応じて):
|
|
546
|
+
- 変更の理由
|
|
547
|
+
- 実装方法
|
|
548
|
+
- 影響範囲
|
|
549
|
+
|
|
550
|
+
関連Issue: #123
|
|
551
|
+
```
|
|
246
552
|
|
|
247
|
-
|
|
553
|
+
種類の例:
|
|
554
|
+
- `feat`: 新機能
|
|
555
|
+
- `fix`: バグ修正
|
|
556
|
+
- `docs`: ドキュメント
|
|
557
|
+
- `style`: コードスタイル
|
|
558
|
+
- `refactor`: リファクタリング
|
|
559
|
+
- `test`: テスト追加
|
|
560
|
+
- `chore`: その他(依存関係更新など)
|
|
561
|
+
|
|
562
|
+
## ロードマップ
|
|
563
|
+
|
|
564
|
+
### 短期目標(v0.2.x)
|
|
565
|
+
- [ ] カスタム区切り文字サポート
|
|
566
|
+
- [ ] ヘッダー行処理
|
|
567
|
+
- [ ] エラーハンドリングの改善
|
|
568
|
+
|
|
569
|
+
### 中期目標(v0.3.x)
|
|
570
|
+
- [ ] ストリーミング処理
|
|
571
|
+
- [ ] 非同期処理サポート
|
|
572
|
+
- [ ] Windows完全サポート
|
|
573
|
+
|
|
574
|
+
### 長期目標(v1.0.x)
|
|
575
|
+
- [ ] 安定したAPI
|
|
576
|
+
- [ ] 包括的なドキュメント
|
|
577
|
+
- [ ] パフォーマンス最適化完了
|
|
578
|
+
|
|
579
|
+
## 参考リンク
|
|
580
|
+
|
|
581
|
+
- [Magnus Documentation](https://docs.rs/magnus/)
|
|
582
|
+
- [rb_sys Documentation](https://docs.rs/rb_sys/)
|
|
583
|
+
- [Ruby Extension Guide](https://docs.ruby-lang.org/en/master/extension_rdoc.html)
|
|
584
|
+
- [Cargo Book](https://doc.rust-lang.org/cargo/)
|
|
585
|
+
- [RubyGems Guides](https://guides.rubygems.org/)
|