dynamicschema 1.0.1 → 2.0.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.
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamicschema
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kristoph Cichocki-Romanov
8
+ autorequire:
8
9
  bindir: bin
9
10
  cert_chain: []
10
- date: 2025-07-28 00:00:00.000000000 Z
11
+ date: 2025-09-06 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: rspec
@@ -43,7 +44,11 @@ description: "The DynamicSchema gem provides a elegant and expressive way to def
43
44
  configurations or interfacing with external APIs, where data structures need to
44
45
  adhere to specific formats and validations. By allowing default values, type constraints,
45
46
  nested schemas, and transformations, DynamicSchema ensures that your data structures
46
- are both robust and flexible."
47
+ are both robust and flexible. \n\nNew in 2.0, DynamicSchema adds DynamicSchema::Struct
48
+ which faciliates effortless definition and construction of complex object hierarchies,
49
+ with optional type coersion and validation. Where DynamicSchema simplified configuration
50
+ and API payload construction, DynamicSchema::Struct simplifies construction of
51
+ complex API reponses."
47
52
  email:
48
53
  - rubygems.org@kristoph.net
49
54
  executables: []
@@ -56,18 +61,22 @@ files:
56
61
  - lib/dynamic_schema.rb
57
62
  - lib/dynamic_schema/buildable.rb
58
63
  - lib/dynamic_schema/builder.rb
59
- - lib/dynamic_schema/builder_methods/conversion.rb
60
- - lib/dynamic_schema/builder_methods/validation.rb
64
+ - lib/dynamic_schema/compiler.rb
65
+ - lib/dynamic_schema/converter.rb
61
66
  - lib/dynamic_schema/definable.rb
62
67
  - lib/dynamic_schema/errors.rb
63
- - lib/dynamic_schema/receiver.rb
64
- - lib/dynamic_schema/resolver.rb
68
+ - lib/dynamic_schema/receiver/base.rb
69
+ - lib/dynamic_schema/receiver/object.rb
70
+ - lib/dynamic_schema/receiver/value.rb
71
+ - lib/dynamic_schema/struct.rb
72
+ - lib/dynamic_schema/validator.rb
65
73
  homepage: https://github.com/EndlessInternational/dynamic_schema
66
74
  licenses:
67
75
  - MIT
68
76
  metadata:
69
77
  source_code_uri: https://github.com/EndlessInternational/dynamic_schema
70
78
  bug_tracker_uri: https://github.com/EndlessInternational/dynamic_schema/issues
79
+ post_install_message:
71
80
  rdoc_options: []
72
81
  require_paths:
73
82
  - lib
@@ -82,7 +91,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
91
  - !ruby/object:Gem::Version
83
92
  version: '0'
84
93
  requirements: []
85
- rubygems_version: 3.6.2
94
+ rubygems_version: 3.5.22
95
+ signing_key:
86
96
  specification_version: 4
87
97
  summary: DynamicSchema is a lightweight and simple yet powerful gem that enables flexible
88
98
  semantic schema definitions for constructing and validating complex configurations
@@ -1,109 +0,0 @@
1
- module DynamicSchema
2
- module BuilderMethods
3
- module Validation
4
-
5
- def validate!( values, schema: self.schema )
6
- traverse_and_validate_values( values, schema: schema ) { | error |
7
- raise error
8
- }
9
- end
10
-
11
- def validate( values, schema: self.schema )
12
- errors = []
13
- traverse_and_validate_values( values, schema: schema ) { | error |
14
- errors << error
15
- }
16
- errors
17
- end
18
-
19
- def valid?( values, schema: self.schema )
20
- traverse_and_validate_values( values, schema: schema ) {
21
- return false
22
- }
23
- return true
24
- end
25
-
26
- protected
27
-
28
- def value_matches_types?( value, types )
29
- type_match = false
30
- Array( types ).each do | type |
31
- type_match = value.is_a?( type )
32
- break if type_match
33
- end
34
- type_match
35
- end
36
-
37
- def traverse_and_validate_values( values, schema:, path: nil, options: nil, &block )
38
- path.chomp( '/' ) if path
39
- unless values.is_a?( Hash )
40
- raise ArgumentError, "The values must always be a Hash."
41
- end
42
-
43
- schema.each do | key, criteria |
44
-
45
- name = criteria[ :as ] || key
46
- value = values[ name ]
47
-
48
- if criteria[ :required ] &&
49
- ( !value || ( value.respond_to?( :empty ) && value.empty? ) )
50
- block.call( RequiredOptionError.new( path: path, key: key ) )
51
- elsif criteria[ :in ]
52
- Array( value ).each do | v |
53
- unless criteria[ :in ].include?( v ) || v.nil?
54
- block.call(
55
- InOptionError.new( path: path, key: key, option: criteria[ :in ], value: v )
56
- )
57
- end
58
- end
59
- elsif !criteria[ :default_assigned ] && !value.nil?
60
- unless criteria[ :array ]
61
- if criteria[ :type ] == Object
62
- traverse_and_validate_values(
63
- values[ name ],
64
- schema: criteria[ :schema ] ||= criteria[ :resolver ]._schema,
65
- path: "#{ ( path || '' ) + ( path ? '/' : '' ) + key.to_s }",
66
- &block
67
- )
68
- else
69
- if criteria[ :type ] && value && !criteria[ :default_assigned ]
70
- unless value_matches_types?( value, criteria[ :type ] )
71
- block.call( IncompatibleTypeError.new(
72
- path: path, key: key, type: criteria[ :type ], value: value
73
- ) )
74
- end
75
- end
76
- end
77
- else
78
- if criteria[ :type ] == Object
79
- groups = Array( value )
80
- groups.each do | group |
81
- traverse_and_validate_values(
82
- group,
83
- schema: criteria[ :schema ] ||= criteria[ :resolver ]._schema,
84
- path: "#{ ( path || '' ) + ( path ? '/' : '' ) + key.to_s }",
85
- &block
86
- )
87
- end
88
- else
89
- if criteria[ :type ] && !criteria[ :default_assigned ]
90
- value_array = Array( value )
91
- value_array.each do | v |
92
- unless value_matches_types?( v, criteria[ :type ] )
93
- block.call( IncompatibleTypeError.new(
94
- path: path, key: key, type: criteria[ :type ], value: v
95
- ) )
96
- end
97
- end
98
- end
99
- end
100
- end
101
- end
102
-
103
- end
104
- nil
105
- end
106
-
107
- end
108
- end
109
- end