dynamicschema 1.0.0.beta03 → 1.0.0.beta04

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5685a6ff1c79676a075f3f7f2cd5863c35466a402c79f3af46c2e164eb37581a
4
- data.tar.gz: 374fbd61c218c4dc4bc6620d18fa3a973d197aa96032c6c2998bb4d3ed8da378
3
+ metadata.gz: 2bbda4319f58741ceca992dec756544aeaa8f9b293afa0bee507ba94636405f4
4
+ data.tar.gz: 67283d904c6d84994d724d2e5a934332f78661bfa1173b0e0a6b4026a1b0a788
5
5
  SHA512:
6
- metadata.gz: 80c7ae562b99ddabf6fe6220a995d845beda151c13683aff13891c47e089700579cb7a099b08a4ac789569ab0499612c2f467222661082b1794cbb75d424a1d9
7
- data.tar.gz: 2da0f6cf54388b6e2e5d3f3ac05214c6f3ea27c8c763fb1ac9a84bbbddbad92d21b29db328c70388653ffd4317a409a58b0165323626e2e2ea2988b188df14c3
6
+ metadata.gz: 2fa81eb8ff0e153e2d9900eea14f26dbdc71ce90bb1b4595c9091330da1d8f6c7fdcd0fa2e8273a64346c08f5baca9a4d2519db7e67b35ea20da6d49a1adde16
7
+ data.tar.gz: 3d86d903925519d2813c379d528ada3a678e80cdf3c24287697c19ab0b3fb9ad9062f21c36bc219f5dceef384fb19bcc1208117416e964906e5cee5b4d9ae7db
data/README.md CHANGED
@@ -194,7 +194,7 @@ schema = DynamicSchema.define do
194
194
  chat_options do
195
195
  model String, default: 'claude-3'
196
196
  max_tokens Integer, default: 1024
197
- temperature, Float, default: 0.5, in: 0..1
197
+ temperature Float, default: 0.5, in: 0..1
198
198
  stream [ TrueClass, FalseClass ]
199
199
  end
200
200
  end
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do | spec |
2
2
 
3
3
  spec.name = 'dynamicschema'
4
- spec.version = '1.0.0.beta03'
4
+ spec.version = '1.0.0.beta04'
5
5
  spec.authors = [ 'Kristoph Cichocki-Romanov' ]
6
6
  spec.email = [ 'rubygems.org@kristoph.net' ]
7
7
 
@@ -15,7 +15,7 @@ module DynamicSchema
15
15
  end
16
16
 
17
17
  def define( &block )
18
- self.schema = Resolver.new( self.schema ).resolve( &block ).schema
18
+ self.schema = Resolver.new( self.schema ).resolve( &block )._schema
19
19
  self
20
20
  end
21
21
 
@@ -61,7 +61,7 @@ module DynamicSchema
61
61
  if criteria[ :type ] == Object
62
62
  traverse_and_validate_values(
63
63
  values[ name ],
64
- schema: criteria[ :schema ] ||= criteria[ :resolver ].schema,
64
+ schema: criteria[ :schema ] ||= criteria[ :resolver ]._schema,
65
65
  path: "#{ ( path || '' ) + ( path ? '/' : '' ) + key.to_s }",
66
66
  &block
67
67
  )
@@ -80,7 +80,7 @@ module DynamicSchema
80
80
  groups.each do | group |
81
81
  traverse_and_validate_values(
82
82
  group,
83
- schema: criteria[ :schema ] ||= criteria[ :resolver ].schema,
83
+ schema: criteria[ :schema ] ||= criteria[ :resolver ]._schema,
84
84
  path: "#{ ( path || '' ) + ( path ? '/' : '' ) + key.to_s }",
85
85
  &block
86
86
  )
@@ -197,7 +197,7 @@ module DynamicSchema
197
197
  Receiver.new(
198
198
  attributes,
199
199
  converters: @converters,
200
- schema: criteria[ :schema ] ||= criteria[ :resolver ].schema
200
+ schema: criteria[ :schema ] ||= criteria[ :resolver ]._schema
201
201
  )
202
202
  end
203
203
  value.instance_eval( &block ) if block
@@ -213,7 +213,7 @@ module DynamicSchema
213
213
  receiver = Receiver.new(
214
214
  a,
215
215
  converters: @converters,
216
- schema: criteria[ :schema ] ||= criteria[ :resolver ].schema
216
+ schema: criteria[ :schema ] ||= criteria[ :resolver ]._schema
217
217
  )
218
218
  receiver.instance_eval( &block ) if block
219
219
  receiver
@@ -22,7 +22,8 @@ module DynamicSchema
22
22
  self
23
23
  end
24
24
 
25
- def schema
25
+ def _schema
26
+
26
27
  if !@resolved && @block
27
28
  @resolved_blocks << @block unless @resolved_blocks.include?( @block )
28
29
  self.instance_eval( &@block )
@@ -31,6 +32,29 @@ module DynamicSchema
31
32
  @schema
32
33
  end
33
34
 
35
+ def _value( name, options )
36
+ name = name.to_sym
37
+ ::Kernel.raise ::NameError, "The name '#{name}' is reserved and cannot be used for parameters." \
38
+ if ::DynamicSchema::Receiver.instance_methods.include?( name )
39
+
40
+ _validate_in!( name, options[ :type ], options[ :in ] ) if options[ :in ]
41
+
42
+ @schema[ name ] = options
43
+ self
44
+ end
45
+
46
+ def _object( name, options = {}, &block )
47
+ name = name.to_sym
48
+ ::Kernel.raise ::NameError, "The name '#{name}' is reserved and cannot be used for parameters." \
49
+ if ::DynamicSchema::Receiver.instance_methods.include?( name )
50
+
51
+ @schema[ name ] = options.merge( {
52
+ type: ::Object,
53
+ resolver: Resolver.new( resolved_blocks: @resolved_blocks ).resolve( &block )
54
+ } )
55
+ self
56
+ end
57
+
34
58
  def method_missing( method, *args, &block )
35
59
  first = args.first
36
60
  options = nil
@@ -58,9 +82,9 @@ module DynamicSchema
58
82
 
59
83
  type = options[ :type ]
60
84
  if type == ::Object || type.nil? && block
61
- _append_object( method, options, &block )
85
+ _object( method, options, &block )
62
86
  else
63
- _append_value( method, options )
87
+ _value( method, options )
64
88
  end
65
89
 
66
90
  end
@@ -92,27 +116,6 @@ module DynamicSchema
92
116
 
93
117
  private
94
118
 
95
- def _append_value( name, options )
96
- ::Kernel.raise ::NameError, "The name '#{name}' is reserved and cannot be used for parameters." \
97
- if ::DynamicSchema::Receiver.instance_methods.include?( name )
98
-
99
- _validate_in!( name, options[ :type ], options[ :in ] ) if options[ :in ]
100
-
101
- @schema[ name ] = options
102
- self
103
- end
104
-
105
- def _append_object( name, options = {}, &block )
106
- ::Kernel.raise ::NameError, "The name '#{name}' is reserved and cannot be used for parameters." \
107
- if ::DynamicSchema::Receiver.instance_methods.include?( name )
108
-
109
- @schema[ name ] = options.merge( {
110
- type: ::Object,
111
- resolver: Resolver.new( resolved_blocks: @resolved_blocks ).resolve( &block )
112
- } )
113
- self
114
- end
115
-
116
119
  def _validate_in!( name, type, in_option )
117
120
  ::Kernel.raise ::TypeError,
118
121
  "The parameter '#{name}' includes the :in option but it does not respond to 'include?'." \
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamicschema
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta03
4
+ version: 1.0.0.beta04
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kristoph Cichocki-Romanov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-27 00:00:00.000000000 Z
11
+ date: 2024-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec