sorbet-schema 0.2.1 → 0.3.0

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: e55d3305b62c159b5843939a7851c7e69614b5a940b0f3ec76d2946e76022611
4
- data.tar.gz: d9574d1aabe4909e7076eeec87e430bd9b2ff4a31c4e1a7f3929a5bcabdc430a
3
+ metadata.gz: 004ea246c450adc69f61c55875a4258a7353c9a5353084b20f3f927dd913a9fc
4
+ data.tar.gz: d9375c481dda06ccb6af6955541993e44f5f1b1a249ab78c3c3624310d888796
5
5
  SHA512:
6
- metadata.gz: e6e17d592757da12f27ac1b7f7a4e33c24b4c81bce5005d6cd7d7e3d6f4ce79c568fcd9d07d86a9af76a61c22bd5bb4b428c0d7e250685932537a31d1c16b301
7
- data.tar.gz: 0062e1b11c2f748f901549ca534ba0f302c58f899975d6f2dceccd50d09b52180d53c2303b08ee06219073ca09b3545452238582889bc1dd17a75e1cbfb124a5
6
+ metadata.gz: c943356484fbc2f8d2bf9539d4432a1a9b3f9904b4e8663165bb152d22ac49548b9e50ff9af5031e74a9c734f1eb3dd3ca65b324d3b09af13c4835bf3a1e15db
7
+ data.tar.gz: 73e261c571f2ad88ef04a7c552d4fa2d808a083e1306819323b13eddb0ec3506405c9690d59b4eab5efa37ac222cf15d2b4d08223ab88dcfc0cccfd18b9f7aff
data/CHANGELOG.md CHANGED
@@ -4,6 +4,24 @@ 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
+
18
+ ## [0.2.2](https://github.com/maxveldink/sorbet-schema/compare/v0.2.1...v0.2.2) (2024-03-12)
19
+
20
+
21
+ ### Bug Fixes
22
+
23
+ * Add unused options parameter to on s ([#40](https://github.com/maxveldink/sorbet-schema/issues/40)) ([f5f8a05](https://github.com/maxveldink/sorbet-schema/commit/f5f8a05c05c2c5959b2f733f4289ddc807075c4d))
24
+
7
25
  ## [0.2.1](https://github.com/maxveldink/sorbet-schema/compare/v0.2.0...v0.2.1) (2024-03-11)
8
26
 
9
27
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sorbet-schema (0.2.1)
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.1"
4
+ VERSION = "0.3.0"
5
5
  end
@@ -9,8 +9,8 @@ module Typed
9
9
  {error: message}
10
10
  end
11
11
 
12
- sig { returns(String) }
13
- def to_json
12
+ sig { params(_options: T::Hash[T.untyped, T.untyped]).returns(String) }
13
+ def to_json(_options = {})
14
14
  JSON.generate(to_h)
15
15
  end
16
16
  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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sorbet-schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max VelDink
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-11 00:00:00.000000000 Z
11
+ date: 2024-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sorbet-result
@@ -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