scheming 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/.solargraph.yml +28 -0
- data/CHANGELOG.md +61 -7
- data/Gemfile +1 -0
- data/Gemfile.lock +34 -1
- data/Rakefile +6 -1
- data/lib/scheming/attribute/list.rb +1 -0
- data/lib/scheming/dsl/tagging.rb +1 -1
- data/lib/scheming/dsl/type_specs.rb +7 -0
- data/lib/scheming/schema/json.rb +13 -1
- data/lib/scheming/type.rb +31 -1
- data/lib/scheming/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 670c2fce2ac13e3ae6d64790ef6fbcad0f0de413c06bb2fc3300e24686315495
|
4
|
+
data.tar.gz: 599cd2a5d28aed9215a011b896a7eb5a207f14f2a7ca55dcd9299abed4100e32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb6bc063479d9b7fc4f3769d966102b0c9fccc971727bb5e72962186227dfb55d3921b40b3a26b5454defc36f1f48cf1afba680b6221ed4b84bee12ae16cce5f
|
7
|
+
data.tar.gz: 711e2a1f8b035ff4aa33dca7955f810cbd7e11774d221f7a2ad0da59623ce5424e4fc02a92fefac78117a1ed37b35fa3a24799547121e97daaebd523a722ef63
|
data/.rubocop.yml
CHANGED
data/.solargraph.yml
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
---
|
2
|
+
include:
|
3
|
+
- "**/*.rb"
|
4
|
+
exclude:
|
5
|
+
- spec/**/*
|
6
|
+
- test/**/*
|
7
|
+
- vendor/**/*
|
8
|
+
- ".bundle/**/*"
|
9
|
+
require: []
|
10
|
+
domains: []
|
11
|
+
reporters:
|
12
|
+
- rubocop
|
13
|
+
- require_not_found
|
14
|
+
- typecheck
|
15
|
+
formatter:
|
16
|
+
rubocop:
|
17
|
+
cops: safe
|
18
|
+
except: []
|
19
|
+
only: []
|
20
|
+
extra_args: []
|
21
|
+
require_paths: [
|
22
|
+
'factory_bot',
|
23
|
+
'json_schemer',
|
24
|
+
'pry',
|
25
|
+
'set'
|
26
|
+
]
|
27
|
+
plugins: []
|
28
|
+
max_files: 5000
|
data/CHANGELOG.md
CHANGED
@@ -1,12 +1,59 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
-
## [0.
|
3
|
+
## [0.7.0] - 2024-05-10
|
4
|
+
|
5
|
+
### Added
|
6
|
+
|
7
|
+
- `Tuple` type added
|
8
|
+
|
9
|
+
#### Example
|
10
|
+
```ruby
|
11
|
+
EmailTemplate = Scheming.object do
|
12
|
+
attribute :id, Integer
|
13
|
+
attribute :data, Tuple(String, Array(String))
|
14
|
+
end
|
15
|
+
|
16
|
+
Scheming::Schema.json(EmailTemplate)
|
17
|
+
# =>
|
18
|
+
{
|
19
|
+
type: 'object',
|
20
|
+
additionalProperties: false,
|
21
|
+
required: %w[id data],
|
22
|
+
properties: {
|
23
|
+
id: { type: 'integer' },
|
24
|
+
data: {
|
25
|
+
type: 'array',
|
26
|
+
prefixItems: [
|
27
|
+
{ type: 'string' },
|
28
|
+
{
|
29
|
+
type: 'array',
|
30
|
+
items: { type: 'string' }
|
31
|
+
}
|
32
|
+
]
|
33
|
+
}
|
34
|
+
}
|
35
|
+
}
|
36
|
+
```
|
37
|
+
|
38
|
+
### Enhancement
|
39
|
+
|
40
|
+
- Added `solorgraph` to the development process and added
|
41
|
+
it's typecheck to the default `rake` task.
|
42
|
+
|
43
|
+
- Reduced string allocations when generating required field
|
44
|
+
names for objects with the JSON schema format.
|
45
|
+
|
46
|
+
### Bugfix
|
47
|
+
|
48
|
+
- Incorrect type syntax corrected as reported by `solargraph`.
|
49
|
+
|
50
|
+
## [0.6.0] - 2024-05-04
|
4
51
|
|
5
52
|
### Added
|
6
53
|
|
7
54
|
- `Union` type added
|
8
55
|
|
9
|
-
|
56
|
+
#### Example
|
10
57
|
```ruby
|
11
58
|
Order = Scheming.object do
|
12
59
|
attribute :id, Union(String, Integer)
|
@@ -15,10 +62,17 @@
|
|
15
62
|
Scheming::Schema.json(Order)
|
16
63
|
# =>
|
17
64
|
{
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
65
|
+
type: 'object',
|
66
|
+
additionalProperties: false,
|
67
|
+
required: %w[id],
|
68
|
+
properties: {
|
69
|
+
id: {
|
70
|
+
oneOf: [
|
71
|
+
{ type: 'string' },
|
72
|
+
{ type: 'integer' }
|
73
|
+
]
|
74
|
+
}
|
75
|
+
}
|
22
76
|
}
|
23
77
|
```
|
24
78
|
|
@@ -48,7 +102,7 @@
|
|
48
102
|
|
49
103
|
- Support for `generic` definitions
|
50
104
|
|
51
|
-
|
105
|
+
#### Example
|
52
106
|
```ruby
|
53
107
|
Point = Scheming.generic do |(type)|
|
54
108
|
Object(x: type, y: type)
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
scheming (0.
|
4
|
+
scheming (0.7.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -17,18 +17,22 @@ GEM
|
|
17
17
|
mutex_m
|
18
18
|
tzinfo (~> 2.0)
|
19
19
|
ast (2.4.2)
|
20
|
+
backport (1.2.0)
|
20
21
|
base64 (0.2.0)
|
22
|
+
benchmark (0.3.0)
|
21
23
|
bigdecimal (3.1.7)
|
22
24
|
coderay (1.1.3)
|
23
25
|
concurrent-ruby (1.2.3)
|
24
26
|
connection_pool (2.4.1)
|
25
27
|
diff-lcs (1.5.1)
|
26
28
|
drb (2.2.1)
|
29
|
+
e2mmap (0.1.0)
|
27
30
|
factory_bot (6.4.6)
|
28
31
|
activesupport (>= 5.0.0)
|
29
32
|
hana (1.3.7)
|
30
33
|
i18n (1.14.4)
|
31
34
|
concurrent-ruby (~> 1.0)
|
35
|
+
jaro_winkler (1.5.6)
|
32
36
|
json (2.7.2)
|
33
37
|
json_schemer (2.2.1)
|
34
38
|
base64
|
@@ -36,10 +40,16 @@ GEM
|
|
36
40
|
hana (~> 1.3)
|
37
41
|
regexp_parser (~> 2.0)
|
38
42
|
simpleidn (~> 0.2)
|
43
|
+
kramdown (2.4.0)
|
44
|
+
rexml
|
45
|
+
kramdown-parser-gfm (1.1.0)
|
46
|
+
kramdown (~> 2.0)
|
39
47
|
language_server-protocol (3.17.0.3)
|
40
48
|
method_source (1.1.0)
|
41
49
|
minitest (5.22.3)
|
42
50
|
mutex_m (0.2.0)
|
51
|
+
nokogiri (1.16.4-x86_64-linux)
|
52
|
+
racc (~> 1.4)
|
43
53
|
parallel (1.24.0)
|
44
54
|
parser (3.3.1.0)
|
45
55
|
ast (~> 2.4.1)
|
@@ -50,7 +60,10 @@ GEM
|
|
50
60
|
racc (1.7.3)
|
51
61
|
rainbow (3.1.1)
|
52
62
|
rake (13.2.1)
|
63
|
+
rbs (2.8.4)
|
53
64
|
regexp_parser (2.9.0)
|
65
|
+
reverse_markdown (2.1.1)
|
66
|
+
nokogiri
|
54
67
|
rexml (3.2.6)
|
55
68
|
rspec (3.13.0)
|
56
69
|
rspec-core (~> 3.13.0)
|
@@ -81,12 +94,31 @@ GEM
|
|
81
94
|
ruby-progressbar (1.13.0)
|
82
95
|
simpleidn (0.2.2)
|
83
96
|
unf (~> 0.1.4)
|
97
|
+
solargraph (0.50.0)
|
98
|
+
backport (~> 1.2)
|
99
|
+
benchmark
|
100
|
+
bundler (~> 2.0)
|
101
|
+
diff-lcs (~> 1.4)
|
102
|
+
e2mmap
|
103
|
+
jaro_winkler (~> 1.5)
|
104
|
+
kramdown (~> 2.3)
|
105
|
+
kramdown-parser-gfm (~> 1.1)
|
106
|
+
parser (~> 3.0)
|
107
|
+
rbs (~> 2.0)
|
108
|
+
reverse_markdown (~> 2.0)
|
109
|
+
rubocop (~> 1.38)
|
110
|
+
thor (~> 1.0)
|
111
|
+
tilt (~> 2.0)
|
112
|
+
yard (~> 0.9, >= 0.9.24)
|
113
|
+
thor (1.3.1)
|
114
|
+
tilt (2.3.0)
|
84
115
|
tzinfo (2.0.6)
|
85
116
|
concurrent-ruby (~> 1.0)
|
86
117
|
unf (0.1.4)
|
87
118
|
unf_ext
|
88
119
|
unf_ext (0.0.9.1)
|
89
120
|
unicode-display_width (2.5.0)
|
121
|
+
yard (0.9.36)
|
90
122
|
|
91
123
|
PLATFORMS
|
92
124
|
x86_64-linux
|
@@ -99,6 +131,7 @@ DEPENDENCIES
|
|
99
131
|
rspec (~> 3.0)
|
100
132
|
rubocop (~> 1.21)
|
101
133
|
scheming!
|
134
|
+
solargraph
|
102
135
|
|
103
136
|
BUNDLED WITH
|
104
137
|
2.4.5
|
data/Rakefile
CHANGED
data/lib/scheming/dsl/tagging.rb
CHANGED
@@ -33,4 +33,11 @@ module Scheming::DSL::TypeSpecs
|
|
33
33
|
end
|
34
34
|
Scheming::Type::Union.new(types)
|
35
35
|
end
|
36
|
+
|
37
|
+
def Tuple(*type_specs) # rubocop:disable Naming/MethodName
|
38
|
+
types = type_specs.map do |type_spec|
|
39
|
+
Scheming::DSL::TypeResolver.resolve(type_spec)
|
40
|
+
end
|
41
|
+
Scheming::Type::Tuple.new(types.freeze)
|
42
|
+
end
|
36
43
|
end
|
data/lib/scheming/schema/json.rb
CHANGED
@@ -31,7 +31,7 @@ module Scheming::Schema
|
|
31
31
|
def required
|
32
32
|
attributes
|
33
33
|
.required
|
34
|
-
.map! { |attr| attr.field_name.
|
34
|
+
.map! { |attr| attr.field_name.name }
|
35
35
|
.freeze
|
36
36
|
end
|
37
37
|
|
@@ -49,6 +49,18 @@ module Scheming::Schema
|
|
49
49
|
def schema = { oneOf: types.map(&:schema).freeze }
|
50
50
|
end
|
51
51
|
|
52
|
+
refine Scheming::Type::Tuple do
|
53
|
+
# @!attribute [r] types
|
54
|
+
# @return [Array<Scheming::Type::Base>]
|
55
|
+
|
56
|
+
def schema
|
57
|
+
{
|
58
|
+
type: 'array',
|
59
|
+
prefixItems: types.map(&:schema).freeze
|
60
|
+
}.freeze
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
52
64
|
refine Scheming::Type::Nullable do
|
53
65
|
# @!attribute [r] type
|
54
66
|
# @return [Scheming::Type::Base]
|
data/lib/scheming/type.rb
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# This is a redundant require statement; however,
|
4
|
+
# for some reason Solargraph will not honor the
|
5
|
+
# path for `set` in it's config. For this reson
|
6
|
+
# we need to require it here to prevent typecheck
|
7
|
+
# errors.
|
8
|
+
require 'set' # rubocop:disable Lint/RedundantRequireStatement
|
9
|
+
|
3
10
|
# = Type
|
4
11
|
#
|
5
12
|
# Everything needed to describe and work
|
@@ -11,7 +18,11 @@ module Scheming::Type
|
|
11
18
|
# Any and all shared functionality comes from
|
12
19
|
# this base type definition.
|
13
20
|
#
|
14
|
-
Base
|
21
|
+
class Base
|
22
|
+
# This class left empty on purpose. Acts
|
23
|
+
# merely as a tag which all types inherit
|
24
|
+
# back to.
|
25
|
+
end
|
15
26
|
|
16
27
|
# = Object Type Definition
|
17
28
|
#
|
@@ -30,6 +41,25 @@ module Scheming::Type
|
|
30
41
|
end
|
31
42
|
end
|
32
43
|
|
44
|
+
# = Tuple Type Definition
|
45
|
+
#
|
46
|
+
# Specifies a type which specifies specific types
|
47
|
+
# in a fixed order. Another way to think of it is
|
48
|
+
# like an [Scheming::Type::Object] but without named
|
49
|
+
# attribute fields.
|
50
|
+
#
|
51
|
+
class Tuple < Base
|
52
|
+
# @return [Array<Scheming::Type::Base>]
|
53
|
+
attr_reader :types
|
54
|
+
|
55
|
+
# @param types [Array<Scheming::Type::Base>]
|
56
|
+
def initialize(types)
|
57
|
+
super()
|
58
|
+
@types = types
|
59
|
+
freeze
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
33
63
|
# = Nullable Type Definition
|
34
64
|
#
|
35
65
|
# Type wrapper that describes a type can be either
|
data/lib/scheming/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scheming
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Falk
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-05-
|
11
|
+
date: 2024-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ergonomic Data Design for the Masses
|
14
14
|
email:
|
@@ -19,6 +19,7 @@ extra_rdoc_files: []
|
|
19
19
|
files:
|
20
20
|
- ".rspec"
|
21
21
|
- ".rubocop.yml"
|
22
|
+
- ".solargraph.yml"
|
22
23
|
- CHANGELOG.md
|
23
24
|
- Gemfile
|
24
25
|
- Gemfile.lock
|