scheming 0.4.0 → 0.5.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 +27 -2
- data/Gemfile.lock +1 -1
- data/README.md +17 -3
- data/lib/scheming/generic.rb +41 -0
- data/lib/scheming/version.rb +1 -1
- data/lib/scheming.rb +4 -0
- 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: b21c99fc59c9fe7da35644b47be93b2d6bba2f13f4ef814008a64c92f2235323
|
4
|
+
data.tar.gz: c0ff8026a852f0b8e4c91bf86aa4a172502a12b3c89dcd693527863dc7cf58aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93fa8e2cd04de2c77495754fe04aa2cbd84070a862835c83ef535a7830b6e41337b401f2e35dbf297434397523e24b50c8cb97063745fe58d61f881114187424
|
7
|
+
data.tar.gz: 61c3cf8462b6d9075e593d00fa76921bbb7958e1ac2590f2a4683ff5c2aeac40b28209e579270eff279cea0261d6d1ea8194a0a87d2ebd3b56f93f8bfc8a2966
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,30 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.5.0] - 2024-05-02
|
4
|
+
|
5
|
+
### Added
|
6
|
+
|
7
|
+
- Support for `generic` definitions
|
8
|
+
|
9
|
+
# Example
|
10
|
+
```ruby
|
11
|
+
Point = Scheming.generic do |(type)|
|
12
|
+
Object(x: type, y: type)
|
13
|
+
end
|
14
|
+
|
15
|
+
Scheming::Schema.json(Point)
|
16
|
+
# =>
|
17
|
+
{
|
18
|
+
type: 'object',
|
19
|
+
additionalProperties: false,
|
20
|
+
required: %i[x y],
|
21
|
+
properties: {
|
22
|
+
x: { type: 'number' },
|
23
|
+
y: { type: 'number' }
|
24
|
+
}
|
25
|
+
}
|
26
|
+
```
|
27
|
+
|
3
28
|
## [0.4.0] - 2024-05-02
|
4
29
|
|
5
30
|
### Breaking Change
|
@@ -35,6 +60,8 @@
|
|
35
60
|
|
36
61
|
### Enhancement
|
37
62
|
|
63
|
+
- Ensure all types produce valid JSON Schema
|
64
|
+
|
38
65
|
## [0.2.0] - 2024-05-01
|
39
66
|
|
40
67
|
### Added
|
@@ -56,8 +83,6 @@
|
|
56
83
|
end
|
57
84
|
```
|
58
85
|
|
59
|
-
- Ensure all types produce valid JSON Schema
|
60
|
-
|
61
86
|
## [0.1.0] - 2024-04-26
|
62
87
|
|
63
88
|
- Initial release
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -27,9 +27,14 @@ LineItem = Scheming.object do
|
|
27
27
|
attribute :item_type, Enum('entertainment', 'staple')
|
28
28
|
end
|
29
29
|
|
30
|
+
Point = Scheming.generic do |(type)|
|
31
|
+
Object(x: type, y: type)
|
32
|
+
end
|
33
|
+
|
30
34
|
Receipt = Scheming.object do
|
31
35
|
attribute :line_items, Array(LineItem)
|
32
36
|
attribute :total, Float
|
37
|
+
attribute :location, Point[Float]
|
33
38
|
end
|
34
39
|
```
|
35
40
|
|
@@ -40,7 +45,7 @@ Scheming::Schema.json(Receipt)
|
|
40
45
|
{
|
41
46
|
type: 'object',
|
42
47
|
additionalProperties: false,
|
43
|
-
required: %i[line_items total],
|
48
|
+
required: %i[line_items total location],
|
44
49
|
properties: {
|
45
50
|
line_items: {
|
46
51
|
type: 'array',
|
@@ -61,12 +66,21 @@ Scheming::Schema.json(Receipt)
|
|
61
66
|
price: { type: 'number' },
|
62
67
|
item_type: {
|
63
68
|
type: 'string',
|
64
|
-
enum: [
|
69
|
+
enum: %w[entertainment staple]
|
65
70
|
}
|
66
71
|
}
|
67
72
|
}
|
68
73
|
},
|
69
|
-
total: { type: 'number' }
|
74
|
+
total: { type: 'number' },
|
75
|
+
location: {
|
76
|
+
type: 'object',
|
77
|
+
additionalProperties: false,
|
78
|
+
required: %i[x y],
|
79
|
+
properties: {
|
80
|
+
x: { type: 'number' },
|
81
|
+
y: { type: 'number' }
|
82
|
+
}
|
83
|
+
}
|
70
84
|
}
|
71
85
|
}
|
72
86
|
```
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# = Generic
|
4
|
+
#
|
5
|
+
# Many types can be "templated" in a way where
|
6
|
+
# some types get swapped in and out. Perhaps
|
7
|
+
# the most common example for this is with a
|
8
|
+
# two dimensional `Point` structure. We could
|
9
|
+
# have a point with `Float` coordinates OR they
|
10
|
+
# could also be `Integer`:
|
11
|
+
#
|
12
|
+
# ```ruby
|
13
|
+
# Object(x: Float, y: Float)
|
14
|
+
# Object(x: Integer, y: Integer)
|
15
|
+
# ```
|
16
|
+
#
|
17
|
+
# Instead of having two defintions we can have
|
18
|
+
# a single generic that defins both:
|
19
|
+
#
|
20
|
+
# ```ruby
|
21
|
+
# Point = Scheming::Generic.new do |(t)|
|
22
|
+
# Object(x: t, y: t)
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# Point[Float]
|
26
|
+
#
|
27
|
+
# Point[Integer]
|
28
|
+
# ```
|
29
|
+
#
|
30
|
+
class Scheming::Generic
|
31
|
+
def initialize(&proto_type)
|
32
|
+
@proto_type = proto_type
|
33
|
+
end
|
34
|
+
|
35
|
+
# @param types [Scheming::Type::Base]
|
36
|
+
def [](*types)
|
37
|
+
Scheming::DSL::DataBuilder
|
38
|
+
.new
|
39
|
+
.instance_exec(types, &@proto_type)
|
40
|
+
end
|
41
|
+
end
|
data/lib/scheming/version.rb
CHANGED
data/lib/scheming.rb
CHANGED
@@ -10,6 +10,7 @@ module Scheming
|
|
10
10
|
require_relative 'scheming/attribute'
|
11
11
|
require_relative 'scheming/type'
|
12
12
|
require_relative 'scheming/schema'
|
13
|
+
require_relative 'scheming/generic'
|
13
14
|
require_relative 'scheming/dsl'
|
14
15
|
|
15
16
|
# @return [Class]
|
@@ -18,4 +19,7 @@ module Scheming
|
|
18
19
|
builder.instance_exec(&)
|
19
20
|
builder.build
|
20
21
|
end
|
22
|
+
|
23
|
+
# @return [Scheming::Generic]
|
24
|
+
def self.generic(&) = Scheming::Generic.new(&)
|
21
25
|
end
|
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.5.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-03 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ergonomic Data Design for the Masses
|
14
14
|
email:
|
@@ -35,6 +35,7 @@ files:
|
|
35
35
|
- lib/scheming/dsl/tagging.rb
|
36
36
|
- lib/scheming/dsl/type_resolver.rb
|
37
37
|
- lib/scheming/dsl/type_specs.rb
|
38
|
+
- lib/scheming/generic.rb
|
38
39
|
- lib/scheming/schema.rb
|
39
40
|
- lib/scheming/schema/json.rb
|
40
41
|
- lib/scheming/type.rb
|