sorbet-schema 0.2.2 → 0.3.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/Gemfile.lock +1 -1
- data/lib/sorbet-schema/version.rb +1 -1
- data/lib/typed/schema.rb +11 -0
- metadata +1 -2
- data/lib/sorbet-schema/struct_ext.rb +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 004ea246c450adc69f61c55875a4258a7353c9a5353084b20f3f927dd913a9fc
|
4
|
+
data.tar.gz: d9375c481dda06ccb6af6955541993e44f5f1b1a249ab78c3c3624310d888796
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c943356484fbc2f8d2bf9539d4432a1a9b3f9904b4e8663165bb152d22ac49548b9e50ff9af5031e74a9c734f1eb3dd3ca65b324d3b09af13c4835bf3a1e15db
|
7
|
+
data.tar.gz: 73e261c571f2ad88ef04a7c552d4fa2d808a083e1306819323b13eddb0ec3506405c9690d59b4eab5efa37ac222cf15d2b4d08223ab88dcfc0cccfd18b9f7aff
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## [0.3.0](https://github.com/maxveldink/sorbet-schema/compare/v0.2.2...v0.3.0) (2024-03-12)
|
8
|
+
|
9
|
+
|
10
|
+
### ⚠ BREAKING CHANGES
|
11
|
+
|
12
|
+
* Remove struct_ext for now
|
13
|
+
|
14
|
+
### Code Refactoring
|
15
|
+
|
16
|
+
* Remove struct_ext for now ([4a505cb](https://github.com/maxveldink/sorbet-schema/commit/4a505cba47b7fd0ae96d76a543f97228a3cd00d7))
|
17
|
+
|
7
18
|
## [0.2.2](https://github.com/maxveldink/sorbet-schema/compare/v0.2.1...v0.2.2) (2024-03-12)
|
8
19
|
|
9
20
|
|
data/Gemfile.lock
CHANGED
data/lib/typed/schema.rb
CHANGED
@@ -2,9 +2,20 @@
|
|
2
2
|
|
3
3
|
module Typed
|
4
4
|
class Schema < T::Struct
|
5
|
+
extend T::Sig
|
5
6
|
include ActsAsComparable
|
6
7
|
|
7
8
|
const :fields, T::Array[Field], default: []
|
8
9
|
const :target, T.class_of(T::Struct)
|
10
|
+
|
11
|
+
sig { params(struct: T.class_of(T::Struct)).returns(Typed::Schema) }
|
12
|
+
def self.from_struct(struct)
|
13
|
+
Typed::Schema.new(
|
14
|
+
target: struct,
|
15
|
+
fields: struct.props.map do |name, properties|
|
16
|
+
Typed::Field.new(name: name, type: properties[:type], required: !properties[:fully_optional])
|
17
|
+
end
|
18
|
+
)
|
19
|
+
end
|
9
20
|
end
|
10
21
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sorbet-schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max VelDink
|
@@ -85,7 +85,6 @@ files:
|
|
85
85
|
- Rakefile
|
86
86
|
- lib/sorbet-schema.rb
|
87
87
|
- lib/sorbet-schema/hash_transformer.rb
|
88
|
-
- lib/sorbet-schema/struct_ext.rb
|
89
88
|
- lib/sorbet-schema/version.rb
|
90
89
|
- lib/typed/coercion.rb
|
91
90
|
- lib/typed/coercion/coercer.rb
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# typed: strict
|
2
|
-
|
3
|
-
module T
|
4
|
-
class Struct
|
5
|
-
extend T::Sig
|
6
|
-
|
7
|
-
sig { returns(Typed::Schema) }
|
8
|
-
def self.create_schema
|
9
|
-
Typed::Schema.new(
|
10
|
-
target: self,
|
11
|
-
fields: props.map do |name, properties|
|
12
|
-
Typed::Field.new(name: name, type: properties[:type], required: !properties[:fully_optional])
|
13
|
-
end
|
14
|
-
)
|
15
|
-
end
|
16
|
-
|
17
|
-
sig { params(hash: Typed::HashSerializer::InputHash).returns(Typed::Serializer::DeserializeResult) }
|
18
|
-
def self.from_hash(hash)
|
19
|
-
Typed::HashSerializer.new(schema: create_schema).deserialize(hash)
|
20
|
-
end
|
21
|
-
|
22
|
-
sig { params(json: String).returns(Typed::Serializer::DeserializeResult) }
|
23
|
-
def self.from_json(json)
|
24
|
-
Typed::JSONSerializer.new(schema: create_schema).deserialize(json)
|
25
|
-
end
|
26
|
-
|
27
|
-
sig { returns(Typed::HashSerializer::OutputHash) }
|
28
|
-
def to_hash
|
29
|
-
Typed::HashSerializer.new(schema: self.class.create_schema).serialize(self)
|
30
|
-
end
|
31
|
-
|
32
|
-
sig { params(_options: T::Hash[T.untyped, T.untyped]).returns(String) }
|
33
|
-
def to_json(_options = {})
|
34
|
-
Typed::JSONSerializer.new(schema: self.class.create_schema).serialize(self)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|