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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ca765b78224dee7c4f7bd3c5b8812e7b2a1f5e2d032449b1e51f70b433cbd078
4
- data.tar.gz: 8ea2d3484c9fdd9e8d224255ada5896beaf85ea5f7b26c2d19570045dc8c2d51
3
+ metadata.gz: 004ea246c450adc69f61c55875a4258a7353c9a5353084b20f3f927dd913a9fc
4
+ data.tar.gz: d9375c481dda06ccb6af6955541993e44f5f1b1a249ab78c3c3624310d888796
5
5
  SHA512:
6
- metadata.gz: 77c4ac65f9c389b81da160c770a016bcdcee0f7473045e61c5a2faf6372564c9305ce961987dbf46edc56f62bfe3152fd33ab59021d5f701e12c3bfb6043a7ca
7
- data.tar.gz: 475a44a999ab80d56537a8bf57358996963ce617e2846ebe024d4ae17df9fa37b3a05be1879a275766c5e43a4e08c805ac3366624f2ab3c52f03a2a8cc7d6591
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sorbet-schema (0.2.2)
4
+ sorbet-schema (0.3.0)
5
5
  sorbet-result (~> 1.1)
6
6
  sorbet-runtime (~> 0.5)
7
7
  sorbet-struct-comparable (~> 1.3)
@@ -1,5 +1,5 @@
1
1
  # typed: strict
2
2
 
3
3
  module SorbetSchema
4
- VERSION = "0.2.2"
4
+ VERSION = "0.3.0"
5
5
  end
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.2.2
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