osv 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/osv/Cargo.lock +402 -0
- data/ext/osv/Cargo.toml +14 -0
- data/ext/osv/src/lib.rs +177 -0
- data/lib/osv/version.rb +1 -1
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c67f4e48abcf76bbbe0fce6513b67464ed550287451f5fa2b4c6e8f83256fef5
|
4
|
+
data.tar.gz: b38342f6e6c43050b45c99ea7f3fba4334423cb10d9df39b23ed054264b35e84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 190d1cfafc93554e5096682f1ce3ec6e9d8049b2669c471db5b27d9190a36500465d798a07e279d73d6e8569c47eaa259f48644a8f1df70138c6f5fc7a826348
|
7
|
+
data.tar.gz: f3c4ed3eac64aaf95e14bf7f5e60b84f2d698db586a2b8c5c6328389e0c067df298b070d4ac78eb91df444ebf23bad2e8ec74f5e7f3314f6ff0c8a248e52b263
|
data/ext/osv/Cargo.lock
ADDED
@@ -0,0 +1,402 @@
|
|
1
|
+
# This file is automatically @generated by Cargo.
|
2
|
+
# It is not intended for manual editing.
|
3
|
+
version = 3
|
4
|
+
|
5
|
+
[[package]]
|
6
|
+
name = "aho-corasick"
|
7
|
+
version = "1.1.3"
|
8
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
9
|
+
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
|
10
|
+
dependencies = [
|
11
|
+
"memchr",
|
12
|
+
]
|
13
|
+
|
14
|
+
[[package]]
|
15
|
+
name = "bindgen"
|
16
|
+
version = "0.69.5"
|
17
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
18
|
+
checksum = "271383c67ccabffb7381723dea0672a673f292304fcb45c01cc648c7a8d58088"
|
19
|
+
dependencies = [
|
20
|
+
"bitflags",
|
21
|
+
"cexpr",
|
22
|
+
"clang-sys",
|
23
|
+
"itertools",
|
24
|
+
"lazy_static",
|
25
|
+
"lazycell",
|
26
|
+
"proc-macro2",
|
27
|
+
"quote",
|
28
|
+
"regex",
|
29
|
+
"rustc-hash",
|
30
|
+
"shlex",
|
31
|
+
"syn",
|
32
|
+
]
|
33
|
+
|
34
|
+
[[package]]
|
35
|
+
name = "bitflags"
|
36
|
+
version = "2.6.0"
|
37
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
38
|
+
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
|
39
|
+
|
40
|
+
[[package]]
|
41
|
+
name = "cexpr"
|
42
|
+
version = "0.6.0"
|
43
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
44
|
+
checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
|
45
|
+
dependencies = [
|
46
|
+
"nom",
|
47
|
+
]
|
48
|
+
|
49
|
+
[[package]]
|
50
|
+
name = "cfg-if"
|
51
|
+
version = "1.0.0"
|
52
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
53
|
+
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
54
|
+
|
55
|
+
[[package]]
|
56
|
+
name = "clang-sys"
|
57
|
+
version = "1.8.1"
|
58
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
59
|
+
checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4"
|
60
|
+
dependencies = [
|
61
|
+
"glob",
|
62
|
+
"libc",
|
63
|
+
"libloading",
|
64
|
+
]
|
65
|
+
|
66
|
+
[[package]]
|
67
|
+
name = "csv"
|
68
|
+
version = "1.3.1"
|
69
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
70
|
+
checksum = "acdc4883a9c96732e4733212c01447ebd805833b7275a73ca3ee080fd77afdaf"
|
71
|
+
dependencies = [
|
72
|
+
"csv-core",
|
73
|
+
"itoa",
|
74
|
+
"ryu",
|
75
|
+
"serde",
|
76
|
+
]
|
77
|
+
|
78
|
+
[[package]]
|
79
|
+
name = "csv-core"
|
80
|
+
version = "0.1.11"
|
81
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
82
|
+
checksum = "5efa2b3d7902f4b634a20cae3c9c4e6209dc4779feb6863329607560143efa70"
|
83
|
+
dependencies = [
|
84
|
+
"memchr",
|
85
|
+
]
|
86
|
+
|
87
|
+
[[package]]
|
88
|
+
name = "either"
|
89
|
+
version = "1.13.0"
|
90
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
91
|
+
checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0"
|
92
|
+
|
93
|
+
[[package]]
|
94
|
+
name = "glob"
|
95
|
+
version = "0.3.1"
|
96
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
97
|
+
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
|
98
|
+
|
99
|
+
[[package]]
|
100
|
+
name = "itertools"
|
101
|
+
version = "0.12.1"
|
102
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
103
|
+
checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569"
|
104
|
+
dependencies = [
|
105
|
+
"either",
|
106
|
+
]
|
107
|
+
|
108
|
+
[[package]]
|
109
|
+
name = "itoa"
|
110
|
+
version = "1.0.14"
|
111
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
112
|
+
checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674"
|
113
|
+
|
114
|
+
[[package]]
|
115
|
+
name = "lazy_static"
|
116
|
+
version = "1.5.0"
|
117
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
118
|
+
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
119
|
+
|
120
|
+
[[package]]
|
121
|
+
name = "lazycell"
|
122
|
+
version = "1.3.0"
|
123
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
124
|
+
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
|
125
|
+
|
126
|
+
[[package]]
|
127
|
+
name = "libc"
|
128
|
+
version = "0.2.169"
|
129
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
130
|
+
checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
|
131
|
+
|
132
|
+
[[package]]
|
133
|
+
name = "libloading"
|
134
|
+
version = "0.8.6"
|
135
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
136
|
+
checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34"
|
137
|
+
dependencies = [
|
138
|
+
"cfg-if",
|
139
|
+
"windows-targets",
|
140
|
+
]
|
141
|
+
|
142
|
+
[[package]]
|
143
|
+
name = "magnus"
|
144
|
+
version = "0.7.1"
|
145
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
146
|
+
checksum = "3d87ae53030f3a22e83879e666cb94e58a7bdf31706878a0ba48752994146dab"
|
147
|
+
dependencies = [
|
148
|
+
"magnus-macros",
|
149
|
+
"rb-sys",
|
150
|
+
"rb-sys-env",
|
151
|
+
"seq-macro",
|
152
|
+
]
|
153
|
+
|
154
|
+
[[package]]
|
155
|
+
name = "magnus-macros"
|
156
|
+
version = "0.6.0"
|
157
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
158
|
+
checksum = "5968c820e2960565f647819f5928a42d6e874551cab9d88d75e3e0660d7f71e3"
|
159
|
+
dependencies = [
|
160
|
+
"proc-macro2",
|
161
|
+
"quote",
|
162
|
+
"syn",
|
163
|
+
]
|
164
|
+
|
165
|
+
[[package]]
|
166
|
+
name = "memchr"
|
167
|
+
version = "2.7.4"
|
168
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
169
|
+
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
170
|
+
|
171
|
+
[[package]]
|
172
|
+
name = "minimal-lexical"
|
173
|
+
version = "0.2.1"
|
174
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
175
|
+
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
176
|
+
|
177
|
+
[[package]]
|
178
|
+
name = "nom"
|
179
|
+
version = "7.1.3"
|
180
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
181
|
+
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
|
182
|
+
dependencies = [
|
183
|
+
"memchr",
|
184
|
+
"minimal-lexical",
|
185
|
+
]
|
186
|
+
|
187
|
+
[[package]]
|
188
|
+
name = "osv"
|
189
|
+
version = "0.1.0"
|
190
|
+
dependencies = [
|
191
|
+
"csv",
|
192
|
+
"magnus",
|
193
|
+
"rb-sys",
|
194
|
+
]
|
195
|
+
|
196
|
+
[[package]]
|
197
|
+
name = "proc-macro2"
|
198
|
+
version = "1.0.92"
|
199
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
200
|
+
checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0"
|
201
|
+
dependencies = [
|
202
|
+
"unicode-ident",
|
203
|
+
]
|
204
|
+
|
205
|
+
[[package]]
|
206
|
+
name = "quote"
|
207
|
+
version = "1.0.37"
|
208
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
209
|
+
checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af"
|
210
|
+
dependencies = [
|
211
|
+
"proc-macro2",
|
212
|
+
]
|
213
|
+
|
214
|
+
[[package]]
|
215
|
+
name = "rb-sys"
|
216
|
+
version = "0.9.103"
|
217
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
218
|
+
checksum = "91dbe37ab6ac2fba187480fb6544b92445e41e5c6f553bf0c33743f3c450a1df"
|
219
|
+
dependencies = [
|
220
|
+
"rb-sys-build",
|
221
|
+
]
|
222
|
+
|
223
|
+
[[package]]
|
224
|
+
name = "rb-sys-build"
|
225
|
+
version = "0.9.103"
|
226
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
227
|
+
checksum = "c4d56a49dcb646b70b758789c0d16c055a386a4f2a3346333abb69850fa860ce"
|
228
|
+
dependencies = [
|
229
|
+
"bindgen",
|
230
|
+
"lazy_static",
|
231
|
+
"proc-macro2",
|
232
|
+
"quote",
|
233
|
+
"regex",
|
234
|
+
"shell-words",
|
235
|
+
"syn",
|
236
|
+
]
|
237
|
+
|
238
|
+
[[package]]
|
239
|
+
name = "rb-sys-env"
|
240
|
+
version = "0.1.2"
|
241
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
242
|
+
checksum = "a35802679f07360454b418a5d1735c89716bde01d35b1560fc953c1415a0b3bb"
|
243
|
+
|
244
|
+
[[package]]
|
245
|
+
name = "regex"
|
246
|
+
version = "1.11.1"
|
247
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
248
|
+
checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
|
249
|
+
dependencies = [
|
250
|
+
"aho-corasick",
|
251
|
+
"memchr",
|
252
|
+
"regex-automata",
|
253
|
+
"regex-syntax",
|
254
|
+
]
|
255
|
+
|
256
|
+
[[package]]
|
257
|
+
name = "regex-automata"
|
258
|
+
version = "0.4.9"
|
259
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
260
|
+
checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
|
261
|
+
dependencies = [
|
262
|
+
"aho-corasick",
|
263
|
+
"memchr",
|
264
|
+
"regex-syntax",
|
265
|
+
]
|
266
|
+
|
267
|
+
[[package]]
|
268
|
+
name = "regex-syntax"
|
269
|
+
version = "0.8.5"
|
270
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
271
|
+
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
|
272
|
+
|
273
|
+
[[package]]
|
274
|
+
name = "rustc-hash"
|
275
|
+
version = "1.1.0"
|
276
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
277
|
+
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
|
278
|
+
|
279
|
+
[[package]]
|
280
|
+
name = "ryu"
|
281
|
+
version = "1.0.18"
|
282
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
283
|
+
checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f"
|
284
|
+
|
285
|
+
[[package]]
|
286
|
+
name = "seq-macro"
|
287
|
+
version = "0.3.5"
|
288
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
289
|
+
checksum = "a3f0bf26fd526d2a95683cd0f87bf103b8539e2ca1ef48ce002d67aad59aa0b4"
|
290
|
+
|
291
|
+
[[package]]
|
292
|
+
name = "serde"
|
293
|
+
version = "1.0.216"
|
294
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
295
|
+
checksum = "0b9781016e935a97e8beecf0c933758c97a5520d32930e460142b4cd80c6338e"
|
296
|
+
dependencies = [
|
297
|
+
"serde_derive",
|
298
|
+
]
|
299
|
+
|
300
|
+
[[package]]
|
301
|
+
name = "serde_derive"
|
302
|
+
version = "1.0.216"
|
303
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
304
|
+
checksum = "46f859dbbf73865c6627ed570e78961cd3ac92407a2d117204c49232485da55e"
|
305
|
+
dependencies = [
|
306
|
+
"proc-macro2",
|
307
|
+
"quote",
|
308
|
+
"syn",
|
309
|
+
]
|
310
|
+
|
311
|
+
[[package]]
|
312
|
+
name = "shell-words"
|
313
|
+
version = "1.1.0"
|
314
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
315
|
+
checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde"
|
316
|
+
|
317
|
+
[[package]]
|
318
|
+
name = "shlex"
|
319
|
+
version = "1.3.0"
|
320
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
321
|
+
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
322
|
+
|
323
|
+
[[package]]
|
324
|
+
name = "syn"
|
325
|
+
version = "2.0.90"
|
326
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
327
|
+
checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31"
|
328
|
+
dependencies = [
|
329
|
+
"proc-macro2",
|
330
|
+
"quote",
|
331
|
+
"unicode-ident",
|
332
|
+
]
|
333
|
+
|
334
|
+
[[package]]
|
335
|
+
name = "unicode-ident"
|
336
|
+
version = "1.0.14"
|
337
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
338
|
+
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
|
339
|
+
|
340
|
+
[[package]]
|
341
|
+
name = "windows-targets"
|
342
|
+
version = "0.52.6"
|
343
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
344
|
+
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
|
345
|
+
dependencies = [
|
346
|
+
"windows_aarch64_gnullvm",
|
347
|
+
"windows_aarch64_msvc",
|
348
|
+
"windows_i686_gnu",
|
349
|
+
"windows_i686_gnullvm",
|
350
|
+
"windows_i686_msvc",
|
351
|
+
"windows_x86_64_gnu",
|
352
|
+
"windows_x86_64_gnullvm",
|
353
|
+
"windows_x86_64_msvc",
|
354
|
+
]
|
355
|
+
|
356
|
+
[[package]]
|
357
|
+
name = "windows_aarch64_gnullvm"
|
358
|
+
version = "0.52.6"
|
359
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
360
|
+
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
|
361
|
+
|
362
|
+
[[package]]
|
363
|
+
name = "windows_aarch64_msvc"
|
364
|
+
version = "0.52.6"
|
365
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
366
|
+
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
|
367
|
+
|
368
|
+
[[package]]
|
369
|
+
name = "windows_i686_gnu"
|
370
|
+
version = "0.52.6"
|
371
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
372
|
+
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
|
373
|
+
|
374
|
+
[[package]]
|
375
|
+
name = "windows_i686_gnullvm"
|
376
|
+
version = "0.52.6"
|
377
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
378
|
+
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
|
379
|
+
|
380
|
+
[[package]]
|
381
|
+
name = "windows_i686_msvc"
|
382
|
+
version = "0.52.6"
|
383
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
384
|
+
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
|
385
|
+
|
386
|
+
[[package]]
|
387
|
+
name = "windows_x86_64_gnu"
|
388
|
+
version = "0.52.6"
|
389
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
390
|
+
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
|
391
|
+
|
392
|
+
[[package]]
|
393
|
+
name = "windows_x86_64_gnullvm"
|
394
|
+
version = "0.52.6"
|
395
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
396
|
+
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
|
397
|
+
|
398
|
+
[[package]]
|
399
|
+
name = "windows_x86_64_msvc"
|
400
|
+
version = "0.52.6"
|
401
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
402
|
+
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
data/ext/osv/Cargo.toml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
[package]
|
2
|
+
name = "osv"
|
3
|
+
version = "0.1.0"
|
4
|
+
edition = "2021"
|
5
|
+
|
6
|
+
[lib]
|
7
|
+
crate-type = ["cdylib"]
|
8
|
+
|
9
|
+
[dependencies]
|
10
|
+
csv = "1.3.1"
|
11
|
+
magnus = { version = "0.7", features = ["rb-sys"] }
|
12
|
+
rb-sys = "0.9"
|
13
|
+
serde = { version = "1.0", features = ["derive"] }
|
14
|
+
serde_magnus = "0.8.1"
|
data/ext/osv/src/lib.rs
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
use magnus::{
|
2
|
+
block::Yield,
|
3
|
+
prelude::*,
|
4
|
+
scan_args::{get_kwargs, scan_args},
|
5
|
+
Error, RString, Ruby, Value,
|
6
|
+
};
|
7
|
+
|
8
|
+
/// Initializes the Ruby extension and defines methods.
|
9
|
+
#[magnus::init]
|
10
|
+
fn init(ruby: &Ruby) -> Result<(), Error> {
|
11
|
+
let module = ruby.define_module("OSV")?;
|
12
|
+
module.define_module_function("for_each", magnus::method!(parse_csv, -1))?;
|
13
|
+
module.define_module_function("for_each_compat", magnus::method!(parse_compat, -1))?;
|
14
|
+
Ok(())
|
15
|
+
}
|
16
|
+
|
17
|
+
/// Helper function to get a readable from either an IO object or a file path
|
18
|
+
fn get_readable(ruby: &Ruby, to_read: Value) -> Result<Box<dyn Read>, Error> {
|
19
|
+
if to_read.is_kind_of(ruby.class_io()) {
|
20
|
+
let reader = RubyIOReader::new(ruby, to_read)?;
|
21
|
+
Ok(Box::new(reader))
|
22
|
+
} else {
|
23
|
+
let path = to_read.to_r_string()?.to_string()?;
|
24
|
+
let file = std::fs::File::open(&path).map_err(|e| {
|
25
|
+
Error::new(
|
26
|
+
ruby.exception_runtime_error(),
|
27
|
+
format!("Failed to open file: {}", e),
|
28
|
+
)
|
29
|
+
})?;
|
30
|
+
Ok(Box::new(file))
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
/// Helper function to create a CSV reader with the given configuration
|
35
|
+
fn create_csv_reader(
|
36
|
+
ruby: &Ruby,
|
37
|
+
to_read: Value,
|
38
|
+
has_headers: bool,
|
39
|
+
delimiter: Option<String>,
|
40
|
+
) -> Result<csv::Reader<Box<dyn Read>>, Error> {
|
41
|
+
let readable = get_readable(ruby, to_read)?;
|
42
|
+
let delimiter = delimiter.unwrap_or_else(|| ",".to_string());
|
43
|
+
|
44
|
+
let rdr = csv::ReaderBuilder::new()
|
45
|
+
.has_headers(has_headers)
|
46
|
+
.delimiter(delimiter.as_bytes()[0])
|
47
|
+
.from_reader(readable);
|
48
|
+
|
49
|
+
Ok(rdr)
|
50
|
+
}
|
51
|
+
|
52
|
+
/// Common setup for CSV parsing, returns the reader and headers
|
53
|
+
fn setup_csv_parser(
|
54
|
+
ruby: &Ruby,
|
55
|
+
to_read: Value,
|
56
|
+
has_headers: bool,
|
57
|
+
delimiter: Option<String>,
|
58
|
+
) -> Result<(csv::Reader<Box<dyn Read>>, Vec<String>), Error> {
|
59
|
+
let mut rdr = create_csv_reader(ruby, to_read, has_headers, delimiter)?;
|
60
|
+
|
61
|
+
let first_row = rdr.headers().unwrap().clone();
|
62
|
+
let num_fields = first_row.len();
|
63
|
+
|
64
|
+
let headers = if has_headers {
|
65
|
+
first_row.iter().map(|h| h.to_string()).collect()
|
66
|
+
} else {
|
67
|
+
(0..num_fields).map(|i| format!("c{}", i)).collect()
|
68
|
+
};
|
69
|
+
|
70
|
+
Ok((rdr, headers))
|
71
|
+
}
|
72
|
+
|
73
|
+
/// Parse common arguments for CSV parsing
|
74
|
+
fn parse_csv_args(args: &[Value]) -> Result<(Value, bool, Option<String>), Error> {
|
75
|
+
let parsed_args = scan_args::<(Value,), (), (), (), _, ()>(args)?;
|
76
|
+
let (to_read,) = parsed_args.required;
|
77
|
+
|
78
|
+
let kwargs = get_kwargs::<_, (), (Option<bool>, Option<String>), ()>(
|
79
|
+
parsed_args.keywords,
|
80
|
+
&[],
|
81
|
+
&["has_headers", "delimiter"],
|
82
|
+
)?;
|
83
|
+
|
84
|
+
let has_headers = kwargs.optional.0.unwrap_or(true);
|
85
|
+
|
86
|
+
Ok((to_read, has_headers, kwargs.optional.1))
|
87
|
+
}
|
88
|
+
|
89
|
+
/// Parses CSV data from a file and yields each row as a hash to the block.
|
90
|
+
fn parse_csv(
|
91
|
+
ruby: &Ruby,
|
92
|
+
rb_self: Value,
|
93
|
+
args: &[Value],
|
94
|
+
) -> Result<Yield<impl Iterator<Item = std::collections::HashMap<String, String>>>, Error> {
|
95
|
+
if !ruby.block_given() {
|
96
|
+
return Ok(Yield::Enumerator(rb_self.enumeratorize("for_each", args)));
|
97
|
+
}
|
98
|
+
|
99
|
+
let (to_read, has_headers, delimiter) = parse_csv_args(args)?;
|
100
|
+
let (rdr, headers) = setup_csv_parser(ruby, to_read, has_headers, delimiter)?;
|
101
|
+
|
102
|
+
let iter = rdr.into_records().filter_map(move |result| {
|
103
|
+
let record = result.ok()?;
|
104
|
+
let mut hash = std::collections::HashMap::new();
|
105
|
+
for (header, field) in headers.iter().zip(record.iter()) {
|
106
|
+
hash.insert(header.to_string(), field.to_string());
|
107
|
+
}
|
108
|
+
Some(hash)
|
109
|
+
});
|
110
|
+
|
111
|
+
Ok(Yield::Iter(iter))
|
112
|
+
}
|
113
|
+
|
114
|
+
fn parse_compat(
|
115
|
+
ruby: &Ruby,
|
116
|
+
rb_self: Value,
|
117
|
+
args: &[Value],
|
118
|
+
) -> Result<Yield<impl Iterator<Item = Vec<String>>>, Error> {
|
119
|
+
if !ruby.block_given() {
|
120
|
+
return Ok(Yield::Enumerator(
|
121
|
+
rb_self.enumeratorize("for_each_compat", args),
|
122
|
+
));
|
123
|
+
}
|
124
|
+
|
125
|
+
let (to_read, has_headers, delimiter) = parse_csv_args(args)?;
|
126
|
+
let (rdr, _) = setup_csv_parser(ruby, to_read, has_headers, delimiter)?;
|
127
|
+
|
128
|
+
let iter = rdr.into_records().filter_map(|result| {
|
129
|
+
result
|
130
|
+
.ok()
|
131
|
+
.map(|record| record.iter().map(|field| field.to_string()).collect())
|
132
|
+
});
|
133
|
+
|
134
|
+
Ok(Yield::Iter(iter))
|
135
|
+
}
|
136
|
+
|
137
|
+
use std::io::Read;
|
138
|
+
|
139
|
+
struct RubyIOReader {
|
140
|
+
io_obj: Value,
|
141
|
+
}
|
142
|
+
|
143
|
+
impl Read for RubyIOReader {
|
144
|
+
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
|
145
|
+
let result: RString = self.io_obj.funcall("read", (buf.len(),)).map_err(|_| {
|
146
|
+
std::io::Error::new(std::io::ErrorKind::Other, "Failed to read from IO")
|
147
|
+
})?;
|
148
|
+
|
149
|
+
// Handle EOF case
|
150
|
+
if result.is_nil() {
|
151
|
+
return Ok(0);
|
152
|
+
}
|
153
|
+
|
154
|
+
let rust_string = result.to_string().map_err(|_| {
|
155
|
+
std::io::Error::new(std::io::ErrorKind::Other, "Failed to convert to string")
|
156
|
+
})?;
|
157
|
+
let bytes = rust_string.as_bytes();
|
158
|
+
|
159
|
+
let bytes_to_copy = rust_string.len().min(buf.len());
|
160
|
+
buf[..bytes_to_copy].copy_from_slice(&bytes[..bytes_to_copy]);
|
161
|
+
|
162
|
+
Ok(bytes_to_copy)
|
163
|
+
}
|
164
|
+
}
|
165
|
+
|
166
|
+
impl RubyIOReader {
|
167
|
+
fn new(ruby: &Ruby, value: Value) -> Result<Self, Error> {
|
168
|
+
if value.is_kind_of(ruby.class_io()) {
|
169
|
+
Ok(RubyIOReader { io_obj: value })
|
170
|
+
} else {
|
171
|
+
Err(Error::new(
|
172
|
+
ruby.exception_runtime_error(),
|
173
|
+
"IO object is not a valid IO object",
|
174
|
+
))
|
175
|
+
}
|
176
|
+
}
|
177
|
+
}
|
data/lib/osv/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: osv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Jaremko
|
@@ -50,7 +50,10 @@ files:
|
|
50
50
|
- Cargo.toml
|
51
51
|
- Gemfile
|
52
52
|
- Rakefile
|
53
|
+
- ext/osv/Cargo.lock
|
54
|
+
- ext/osv/Cargo.toml
|
53
55
|
- ext/osv/extconf.rb
|
56
|
+
- ext/osv/src/lib.rs
|
54
57
|
- lib/osv.rb
|
55
58
|
- lib/osv/version.rb
|
56
59
|
homepage: https://github.com/njaremko/osv
|