ruby_llm-schema 0.1.0 → 0.1.6

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: f2af8bd6f95696f6f8ab70e9d83637772bc1cdd3bf6fea283d2d7389a31a156e
4
- data.tar.gz: ae39967ea90ec3a189eb0399bcc58da9d3da33d94093d98934bdda71485d70b0
3
+ metadata.gz: d6c0f93a31976be978ea63b955ff89a9d9fa3e2c927457396ecda8a104d5a8df
4
+ data.tar.gz: fc2113a8e86d73ac532d6ab03d95ea234678196fbe400a8e2656a9da6f6930ba
5
5
  SHA512:
6
- metadata.gz: 5d5903e14886b65431d92dfd511a61db51a824b03da19caf6fe062d1384ae12f4ec1a5004f2b1d2974ed1b32da8b91ca45243c5b299014b4a845828d4722506f
7
- data.tar.gz: bb501057362585d42a11abfdc4de38a7743b8944699fcfd24e234655f478d6999c49c3d2659a7538e89d279a56f7dfea51e1577694f1941b8b97fbfa65758a44
6
+ metadata.gz: e49c81df9deed1904351e88d1a887fa58ed321ee9a96d03ca1fc3bebb5f981bfb263634e3005286f1c774322ec12943ffc7cb3f69ac42b57839290e6e6407f6c
7
+ data.tar.gz: 3bb762ef34a9cc9b36c9bf4ad8ee74d659dc3dbdf26169b3654e896fab2d33f8e82e9d5976d228b6766c139e631af1f0aea547e988138d95de5db4a3d889ab71
data/README.md CHANGED
@@ -7,7 +7,7 @@ A Ruby DSL for creating JSON schemas with a clean, Rails-inspired API. Perfect f
7
7
  ```ruby
8
8
  class PersonSchema < RubyLLM::Schema
9
9
  string :name, description: "Person's full name"
10
- number :age, description: "Age in years"
10
+ number :age, description: "Age in years", minimum: 0, maximum: 120
11
11
  boolean :active, required: false
12
12
 
13
13
  object :address do
@@ -20,7 +20,7 @@ class PersonSchema < RubyLLM::Schema
20
20
 
21
21
  array :contacts do
22
22
  object do
23
- string :email
23
+ string :email, format: "email"
24
24
  string :phone, required: false
25
25
  end
26
26
  end
@@ -130,7 +130,14 @@ puts person_schema.to_json
130
130
  string :name # Required string
131
131
  string :title, required: false # Optional string
132
132
  string :status, enum: ["on", "off"] # String with enum values
133
+ string :email, format: "email" # String with format validation
134
+ string :code, min_length: 3, max_length: 10 # String with length constraints
135
+ string :pattern_field, pattern: "\\d+" # String with regex pattern
136
+
133
137
  number :count # Required number
138
+ number :price, minimum: 0, maximum: 100 # Number with range constraints
139
+ number :amount, multiple_of: 0.01 # Number with precision constraints
140
+
134
141
  integer :id # Required integer
135
142
  boolean :active # Required boolean
136
143
  null :placeholder # Null type
@@ -141,6 +148,7 @@ null :placeholder # Null type
141
148
  ```ruby
142
149
  array :tags, of: :string # Array of strings
143
150
  array :scores, of: :number # Array of numbers
151
+ array :items, min_items: 1, max_items: 10 # Array with size constraints
144
152
 
145
153
  array :items do # Array of objects
146
154
  object do
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RubyLlm
4
4
  class Schema
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.6"
6
6
  end
7
7
  end
@@ -30,16 +30,34 @@ module RubyLLM
30
30
  end
31
31
 
32
32
  def strict(value = nil)
33
- return @strict ||= true if value.nil?
33
+ if value.nil?
34
+ return @strict.nil? ? (@strict = true) : @strict
35
+ end
34
36
  @strict = value
35
37
  end
36
38
 
37
- def string(name = nil, enum: nil, description: nil, required: true)
38
- add_property(name, build_property_schema(:string, enum: enum, description: description), required: required)
39
+ def string(name = nil, enum: nil, description: nil, required: true, min_length: nil, max_length: nil, pattern: nil, format: nil)
40
+ options = {
41
+ enum: enum,
42
+ description: description,
43
+ minLength: min_length,
44
+ maxLength: max_length,
45
+ pattern: pattern,
46
+ format: format
47
+ }.compact
48
+
49
+ add_property(name, build_property_schema(:string, **options), required: required)
39
50
  end
40
51
 
41
- def number(name = nil, description: nil, required: true)
42
- add_property(name, build_property_schema(:number, description: description), required: required)
52
+ def number(name = nil, description: nil, required: true, minimum: nil, maximum: nil, multiple_of: nil)
53
+ options = {
54
+ description: description,
55
+ minimum: minimum,
56
+ maximum: maximum,
57
+ multipleOf: multiple_of
58
+ }.compact
59
+
60
+ add_property(name, build_property_schema(:number, **options), required: required)
43
61
  end
44
62
 
45
63
  def integer(name = nil, description: nil, required: true)
@@ -58,13 +76,15 @@ module RubyLLM
58
76
  add_property(name, build_property_schema(:object, description: description, &block), required: required)
59
77
  end
60
78
 
61
- def array(name, of: nil, description: nil, required: true, &block)
79
+ def array(name, of: nil, description: nil, required: true, min_items: nil, max_items: nil, &block)
62
80
  items = determine_array_items(of, &block)
63
81
 
64
82
  add_property(name, {
65
83
  type: "array",
66
84
  description: description,
67
- items: items
85
+ items: items,
86
+ minItems: min_items,
87
+ maxItems: max_items
68
88
  }.compact, required: required)
69
89
  end
70
90
 
@@ -77,6 +97,13 @@ module RubyLLM
77
97
  }.compact, required: required)
78
98
  end
79
99
 
100
+ def optional(name, description: nil, &block)
101
+ any_of(name, description: description) do
102
+ instance_eval(&block)
103
+ null
104
+ end
105
+ end
106
+
80
107
  def define(name, &)
81
108
  sub_schema = Class.new(Schema)
82
109
  sub_schema.class_eval(&)
@@ -107,11 +134,31 @@ module RubyLLM
107
134
  def build_property_schema(type, **options, &)
108
135
  case type
109
136
  when :string
110
- {type: "string", enum: options[:enum], description: options[:description]}.compact
137
+ {
138
+ type: "string",
139
+ enum: options[:enum],
140
+ description: options[:description],
141
+ minLength: options[:minLength],
142
+ maxLength: options[:maxLength],
143
+ pattern: options[:pattern],
144
+ format: options[:format]
145
+ }.compact
111
146
  when :number
112
- {type: "number", description: options[:description]}.compact
147
+ {
148
+ type: "number",
149
+ description: options[:description],
150
+ minimum: options[:minimum],
151
+ maximum: options[:maximum],
152
+ multipleOf: options[:multipleOf]
153
+ }.compact
113
154
  when :integer
114
- {type: "integer", description: options[:description]}.compact
155
+ {
156
+ type: "integer",
157
+ description: options[:description],
158
+ minimum: options[:minimum],
159
+ maximum: options[:maximum],
160
+ multipleOf: options[:multipleOf]
161
+ }.compact
115
162
  when :boolean
116
163
  {type: "boolean", description: options[:description]}.compact
117
164
  when :null
@@ -178,7 +225,7 @@ module RubyLLM
178
225
 
179
226
  {
180
227
  name: @name,
181
- description: @description,
228
+ description: @description || self.class.description,
182
229
  schema: {
183
230
  :type => "object",
184
231
  :properties => self.class.properties,
@@ -1,9 +1,24 @@
1
1
  namespace :release do
2
2
  desc "Release a new version of the gem"
3
3
  task :version do
4
- puts "Enter the new version: "
5
- version = gets.chomp
6
- system "git tag v#{version}"
4
+ # Load the current version from version.rb
5
+ require_relative '../../lib/ruby_llm/schema/version'
6
+ version = RubyLlm::Schema::VERSION
7
+
8
+ puts "Releasing version #{version}..."
9
+
10
+ # Prompt for release message
11
+ print "Enter release message (optional): "
12
+ release_message = STDIN.gets.chomp
13
+
14
+ # Create git tag with message
15
+ if release_message.empty?
16
+ system "git tag v#{version}"
17
+ else
18
+ system "git tag -a v#{version} -m \"#{release_message}\""
19
+ end
20
+
21
+ system "git push origin main"
7
22
  system "git push origin v#{version}"
8
23
 
9
24
  system "gem build ruby_llm-schema.gemspec"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_llm-schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Friis
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-06-16 00:00:00.000000000 Z
10
+ date: 2025-08-08 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rspec
@@ -44,7 +44,6 @@ extensions: []
44
44
  extra_rdoc_files: []
45
45
  files:
46
46
  - ".rspec"
47
- - ".rspec_status"
48
47
  - LICENSE.txt
49
48
  - README.md
50
49
  - Rakefile
data/.rspec_status DELETED
@@ -1,55 +0,0 @@
1
- example_id | status | run_time |
2
- --------------------------------------------------------- | ------ | --------------- |
3
- ./spec/ruby_llm/schema_class_inheritance_spec.rb[1:1:1:1] | passed | 0.0002 seconds |
4
- ./spec/ruby_llm/schema_class_inheritance_spec.rb[1:1:1:2] | passed | 0.00004 seconds |
5
- ./spec/ruby_llm/schema_class_inheritance_spec.rb[1:1:2:1] | passed | 0.00003 seconds |
6
- ./spec/ruby_llm/schema_class_inheritance_spec.rb[1:1:2:2] | passed | 0.00027 seconds |
7
- ./spec/ruby_llm/schema_class_inheritance_spec.rb[1:1:3:1] | passed | 0.00004 seconds |
8
- ./spec/ruby_llm/schema_class_inheritance_spec.rb[1:1:3:2] | passed | 0.00003 seconds |
9
- ./spec/ruby_llm/schema_class_inheritance_spec.rb[1:1:4:1] | passed | 0.00003 seconds |
10
- ./spec/ruby_llm/schema_class_inheritance_spec.rb[1:1:4:2] | passed | 0.00003 seconds |
11
- ./spec/ruby_llm/schema_class_inheritance_spec.rb[1:2:1] | passed | 0.00044 seconds |
12
- ./spec/ruby_llm/schema_class_inheritance_spec.rb[1:3:1] | passed | 0.00058 seconds |
13
- ./spec/ruby_llm/schema_factory_spec.rb[1:1:1:1] | passed | 0.00004 seconds |
14
- ./spec/ruby_llm/schema_factory_spec.rb[1:1:1:2] | passed | 0.00003 seconds |
15
- ./spec/ruby_llm/schema_factory_spec.rb[1:1:2:1] | passed | 0.00004 seconds |
16
- ./spec/ruby_llm/schema_factory_spec.rb[1:1:2:2] | passed | 0.00003 seconds |
17
- ./spec/ruby_llm/schema_factory_spec.rb[1:1:3:1] | passed | 0.00003 seconds |
18
- ./spec/ruby_llm/schema_factory_spec.rb[1:1:3:2] | passed | 0.00003 seconds |
19
- ./spec/ruby_llm/schema_factory_spec.rb[1:1:4:1] | passed | 0.00003 seconds |
20
- ./spec/ruby_llm/schema_factory_spec.rb[1:1:4:2] | passed | 0.00003 seconds |
21
- ./spec/ruby_llm/schema_factory_spec.rb[1:2:1] | passed | 0.00005 seconds |
22
- ./spec/ruby_llm/schema_factory_spec.rb[1:3:1] | passed | 0.00004 seconds |
23
- ./spec/ruby_llm/schema_helpers_spec.rb[1:1:1:1] | passed | 0.00004 seconds |
24
- ./spec/ruby_llm/schema_helpers_spec.rb[1:1:1:2] | passed | 0.00003 seconds |
25
- ./spec/ruby_llm/schema_helpers_spec.rb[1:1:2:1] | passed | 0.00003 seconds |
26
- ./spec/ruby_llm/schema_helpers_spec.rb[1:1:2:2] | passed | 0.00003 seconds |
27
- ./spec/ruby_llm/schema_helpers_spec.rb[1:1:3:1] | passed | 0.00003 seconds |
28
- ./spec/ruby_llm/schema_helpers_spec.rb[1:1:3:2] | passed | 0.00003 seconds |
29
- ./spec/ruby_llm/schema_helpers_spec.rb[1:1:4:1] | passed | 0.00003 seconds |
30
- ./spec/ruby_llm/schema_helpers_spec.rb[1:1:4:2] | passed | 0.00003 seconds |
31
- ./spec/ruby_llm/schema_helpers_spec.rb[1:2:1] | passed | 0.00005 seconds |
32
- ./spec/ruby_llm/schema_helpers_spec.rb[1:3:1] | passed | 0.00003 seconds |
33
- ./spec/ruby_llm/schema_spec.rb[1:1:1] | passed | 0.00018 seconds |
34
- ./spec/ruby_llm/schema_spec.rb[1:1:2] | passed | 0.00004 seconds |
35
- ./spec/ruby_llm/schema_spec.rb[1:1:3] | passed | 0.00003 seconds |
36
- ./spec/ruby_llm/schema_spec.rb[1:1:4] | passed | 0.00002 seconds |
37
- ./spec/ruby_llm/schema_spec.rb[1:1:5] | passed | 0.00002 seconds |
38
- ./spec/ruby_llm/schema_spec.rb[1:1:6] | passed | 0.0006 seconds |
39
- ./spec/ruby_llm/schema_spec.rb[1:2:1] | passed | 0.00004 seconds |
40
- ./spec/ruby_llm/schema_spec.rb[1:2:2] | passed | 0.00007 seconds |
41
- ./spec/ruby_llm/schema_spec.rb[1:2:3] | passed | 0.00004 seconds |
42
- ./spec/ruby_llm/schema_spec.rb[1:3:1] | passed | 0.00005 seconds |
43
- ./spec/ruby_llm/schema_spec.rb[1:3:2] | passed | 0.00004 seconds |
44
- ./spec/ruby_llm/schema_spec.rb[1:3:3] | passed | 0.00004 seconds |
45
- ./spec/ruby_llm/schema_spec.rb[1:4:1] | passed | 0.00006 seconds |
46
- ./spec/ruby_llm/schema_spec.rb[1:5:1] | passed | 0.00003 seconds |
47
- ./spec/ruby_llm/schema_spec.rb[1:5:2] | passed | 0.00057 seconds |
48
- ./spec/ruby_llm/schema_spec.rb[1:5:3] | passed | 0.00023 seconds |
49
- ./spec/ruby_llm/schema_spec.rb[1:6:1] | passed | 0.00038 seconds |
50
- ./spec/ruby_llm/schema_spec.rb[1:6:2] | passed | 0.00003 seconds |
51
- ./spec/ruby_llm/schema_spec.rb[1:7:1:1] | passed | 0.00021 seconds |
52
- ./spec/ruby_llm/schema_spec.rb[1:7:1:2] | passed | 0.00006 seconds |
53
- ./spec/ruby_llm/schema_spec.rb[1:7:2:1] | passed | 0.00005 seconds |
54
- ./spec/ruby_llm/schema_spec.rb[1:8:1] | passed | 0.00044 seconds |
55
- ./spec/ruby_llm/schema_spec.rb[1:8:2] | passed | 0.00008 seconds |