lluminary 0.1.3 → 0.2.0

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.
@@ -218,6 +218,261 @@ RSpec.describe Lluminary::Schema do
218
218
  errors = schema.validate(numbers: [1, "2", 3])
219
219
  expect(errors).to contain_exactly("Numbers[1] must be an Integer")
220
220
  end
221
+
222
+ it "supports hashes inside arrays" do
223
+ schema.array(:users) do
224
+ hash do
225
+ string :name
226
+ integer :age
227
+ end
228
+ end
229
+
230
+ expect(schema.fields[:users]).to eq(
231
+ {
232
+ type: :array,
233
+ description: nil,
234
+ element_type: {
235
+ type: :hash,
236
+ description: nil,
237
+ fields: {
238
+ name: {
239
+ type: :string,
240
+ description: nil
241
+ },
242
+ age: {
243
+ type: :integer,
244
+ description: nil
245
+ }
246
+ }
247
+ }
248
+ }
249
+ )
250
+ end
251
+
252
+ it "validates hashes inside arrays" do
253
+ schema.array(:users) do
254
+ hash do
255
+ string :name
256
+ integer :age
257
+ end
258
+ end
259
+
260
+ errors =
261
+ schema.validate(
262
+ users: [
263
+ { name: "Alice", age: 30 },
264
+ { name: 123, age: "invalid" }, # name should be string, age should be integer
265
+ { name: "Bob", age: 25 }
266
+ ]
267
+ )
268
+
269
+ expect(errors).to contain_exactly(
270
+ "Users[1][name] must be a String",
271
+ "Users[1][age] must be an Integer"
272
+ )
273
+ end
274
+ end
275
+
276
+ describe "#hash" do
277
+ it "requires a block for hash fields" do
278
+ expect { schema.hash(:config) }.to raise_error(
279
+ ArgumentError,
280
+ "Hash fields must be defined with a block"
281
+ )
282
+ end
283
+
284
+ it "adds a hash field with nested fields to the schema" do
285
+ schema.hash(:config, description: "Configuration") do
286
+ string :host, description: "The server hostname"
287
+ integer :port
288
+ end
289
+
290
+ expect(schema.fields).to eq(
291
+ {
292
+ config: {
293
+ type: :hash,
294
+ description: "Configuration",
295
+ fields: {
296
+ host: {
297
+ type: :string,
298
+ description: "The server hostname"
299
+ },
300
+ port: {
301
+ type: :integer,
302
+ description: nil
303
+ }
304
+ }
305
+ }
306
+ }
307
+ )
308
+ end
309
+
310
+ it "validates hash values" do
311
+ schema.hash(:config) do
312
+ string :host
313
+ integer :port
314
+ end
315
+
316
+ errors =
317
+ schema.validate(
318
+ config: {
319
+ host: 123, # should be string
320
+ port: "80" # should be integer
321
+ }
322
+ )
323
+
324
+ expect(errors).to contain_exactly(
325
+ "Config[host] must be a String",
326
+ "Config[port] must be an Integer"
327
+ )
328
+ end
329
+
330
+ it "validates that value is a hash" do
331
+ schema.hash(:config) { string :host }
332
+
333
+ errors = schema.validate(config: "not a hash")
334
+ expect(errors).to contain_exactly("Config must be a Hash")
335
+ end
336
+
337
+ it "supports nested hashes" do
338
+ schema.hash(:config) do
339
+ string :name
340
+ hash :database do
341
+ string :host
342
+ integer :port
343
+ hash :credentials do
344
+ string :username
345
+ string :password
346
+ end
347
+ end
348
+ end
349
+
350
+ expect(schema.fields[:config]).to eq(
351
+ {
352
+ type: :hash,
353
+ description: nil,
354
+ fields: {
355
+ name: {
356
+ type: :string,
357
+ description: nil
358
+ },
359
+ database: {
360
+ type: :hash,
361
+ description: nil,
362
+ fields: {
363
+ host: {
364
+ type: :string,
365
+ description: nil
366
+ },
367
+ port: {
368
+ type: :integer,
369
+ description: nil
370
+ },
371
+ credentials: {
372
+ type: :hash,
373
+ description: nil,
374
+ fields: {
375
+ username: {
376
+ type: :string,
377
+ description: nil
378
+ },
379
+ password: {
380
+ type: :string,
381
+ description: nil
382
+ }
383
+ }
384
+ }
385
+ }
386
+ }
387
+ }
388
+ }
389
+ )
390
+ end
391
+
392
+ it "validates nested hashes" do
393
+ schema.hash(:config) do
394
+ string :name
395
+ hash :database do
396
+ string :host
397
+ integer :port
398
+ hash :credentials do
399
+ string :username
400
+ string :password
401
+ end
402
+ end
403
+ end
404
+
405
+ errors =
406
+ schema.validate(
407
+ config: {
408
+ name: "test",
409
+ database: {
410
+ host: 123, # should be string
411
+ port: "80", # should be integer
412
+ credentials: {
413
+ username: 456, # should be string
414
+ password: 789 # should be string
415
+ }
416
+ }
417
+ }
418
+ )
419
+
420
+ expect(errors).to contain_exactly(
421
+ "Config[database][host] must be a String",
422
+ "Config[database][port] must be an Integer",
423
+ "Config[database][credentials][username] must be a String",
424
+ "Config[database][credentials][password] must be a String"
425
+ )
426
+ end
427
+
428
+ it "supports arrays inside hashes" do
429
+ schema.hash(:config) do
430
+ string :name
431
+ array :tags do
432
+ string
433
+ end
434
+ end
435
+
436
+ expect(schema.fields[:config]).to eq(
437
+ {
438
+ type: :hash,
439
+ description: nil,
440
+ fields: {
441
+ name: {
442
+ type: :string,
443
+ description: nil
444
+ },
445
+ tags: {
446
+ type: :array,
447
+ description: nil,
448
+ element_type: {
449
+ type: :string,
450
+ description: nil
451
+ }
452
+ }
453
+ }
454
+ }
455
+ )
456
+ end
457
+
458
+ it "validates arrays inside hashes" do
459
+ schema.hash(:config) do
460
+ string :name
461
+ array :tags do
462
+ string
463
+ end
464
+ end
465
+
466
+ errors =
467
+ schema.validate(
468
+ config: {
469
+ name: "test",
470
+ tags: ["valid", 123, "also valid"] # second element should be string
471
+ }
472
+ )
473
+
474
+ expect(errors).to contain_exactly("Config[tags][1] must be a String")
475
+ end
221
476
  end
222
477
 
223
478
  describe "primitive types" do
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lluminary
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Doug Hughes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-04-23 00:00:00.000000000 Z
11
+ date: 2025-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '5.2'
20
+ - - "<"
18
21
  - !ruby/object:Gem::Version
19
- version: 5.2.0
22
+ version: '9'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '5.2'
30
+ - - "<"
25
31
  - !ruby/object:Gem::Version
26
- version: 5.2.0
32
+ version: '9'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: aws-sdk-bedrock
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +72,20 @@ dependencies:
66
72
  - - "~>"
67
73
  - !ruby/object:Gem::Version
68
74
  version: '6.3'
75
+ - !ruby/object:Gem::Dependency
76
+ name: awesome_print
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '1.9'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '1.9'
69
89
  - !ruby/object:Gem::Dependency
70
90
  name: dotenv
71
91
  requirement: !ruby/object:Gem::Requirement
@@ -150,20 +170,6 @@ dependencies:
150
170
  - - "~>"
151
171
  - !ruby/object:Gem::Version
152
172
  version: '6.2'
153
- - !ruby/object:Gem::Dependency
154
- name: awesome_print
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - "~>"
158
- - !ruby/object:Gem::Version
159
- version: '1.9'
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - "~>"
165
- - !ruby/object:Gem::Version
166
- version: '1.9'
167
173
  description: 'Lluminary is a framework for building applications that leverage Large
168
174
  Language Models. It provides a structured way to define tasks, manage prompts, and
169
175
  handle LLM interactions.
@@ -194,6 +200,7 @@ files:
194
200
  - lib/lluminary/validation_error.rb
195
201
  - lib/lluminary/version.rb
196
202
  - spec/examples/analyze_text_spec.rb
203
+ - spec/examples/character_profiler_spec.rb
197
204
  - spec/examples/color_analyzer_spec.rb
198
205
  - spec/examples/content_analyzer_spec.rb
199
206
  - spec/examples/historical_event_analyzer_spec.rb