scheming 0.2.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +39 -2
- data/Gemfile +1 -0
- data/Gemfile.lock +7 -1
- data/README.md +6 -5
- data/lib/scheming/dsl/data_builder.rb +8 -5
- data/lib/scheming/dsl/tagging.rb +47 -0
- data/lib/scheming/dsl.rb +1 -0
- data/lib/scheming/schema/json.rb +2 -2
- data/lib/scheming/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9200950b341609a10673661255198aacf8012bdb89b89868d66eed91aa11c395
|
4
|
+
data.tar.gz: 175243bb9bd5204b93b5f59f2e0b403163c86ed745a01a23c2e987bc2aab2813
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c83e51b6db0200f0d222250e690696061ecf581bad11e4c5916df828cfef2d6ae01da50349d7a1cdea2097b7a235fe19950c48ec0b11f628522ed734a100e48
|
7
|
+
data.tar.gz: b35ebaf5d8d1a30b1538471d153a7da1ed648037c84c89ec2132742bad94fcfee0b0d4744b0c82b3f36de924d30a39579e881a812f4d1ba6fc3bff9c46283415
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,39 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
-
## [0.
|
3
|
+
## [0.4.0] - 2024-05-02
|
4
4
|
|
5
|
-
|
5
|
+
### Breaking Change
|
6
|
+
|
7
|
+
- Opting for a `tag` system to work with attributes instead
|
8
|
+
of a blanket lexical scope like `optional` to work with
|
9
|
+
attributes. The long term goal is to expand out the tagging
|
10
|
+
system so that it can support much more than we can
|
11
|
+
anticipate today.
|
12
|
+
|
13
|
+
# Example:
|
14
|
+
```ruby
|
15
|
+
LineItem = Scheming.object do
|
16
|
+
attribute :id, Integer
|
17
|
+
attribute :name, String
|
18
|
+
attribute :taxable, :bool
|
19
|
+
attribute :price, Float
|
20
|
+
|
21
|
+
tag(:optional)
|
22
|
+
attribute :desc, Nullable(String)
|
23
|
+
|
24
|
+
tag(:optional)
|
25
|
+
attribute :item_type, Enum('entertainment', 'staple')
|
26
|
+
end
|
27
|
+
|
28
|
+
## [0.3.0] - 2024-05-01
|
29
|
+
|
30
|
+
### Bugfix
|
31
|
+
|
32
|
+
- JSON Schema for Float was `numeric` instead of `number`
|
33
|
+
|
34
|
+
- JSON Schema production of `Enum` **must** be an array
|
35
|
+
|
36
|
+
### Enhancement
|
6
37
|
|
7
38
|
## [0.2.0] - 2024-05-01
|
8
39
|
|
@@ -24,3 +55,9 @@
|
|
24
55
|
attribute :item_type, Enum('entertainment', 'staple')
|
25
56
|
end
|
26
57
|
```
|
58
|
+
|
59
|
+
- Ensure all types produce valid JSON Schema
|
60
|
+
|
61
|
+
## [0.1.0] - 2024-04-26
|
62
|
+
|
63
|
+
- Initial release
|
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.4.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -16,6 +16,8 @@ GEM
|
|
16
16
|
minitest (>= 5.1)
|
17
17
|
mutex_m
|
18
18
|
tzinfo (~> 2.0)
|
19
|
+
addressable (2.8.6)
|
20
|
+
public_suffix (>= 2.0.2, < 6.0)
|
19
21
|
ast (2.4.2)
|
20
22
|
base64 (0.2.0)
|
21
23
|
bigdecimal (3.1.7)
|
@@ -29,6 +31,8 @@ GEM
|
|
29
31
|
i18n (1.14.4)
|
30
32
|
concurrent-ruby (~> 1.0)
|
31
33
|
json (2.7.2)
|
34
|
+
json-schema (4.3.0)
|
35
|
+
addressable (>= 2.8)
|
32
36
|
language_server-protocol (3.17.0.3)
|
33
37
|
method_source (1.1.0)
|
34
38
|
minitest (5.22.3)
|
@@ -40,6 +44,7 @@ GEM
|
|
40
44
|
pry (0.14.2)
|
41
45
|
coderay (~> 1.1)
|
42
46
|
method_source (~> 1.0)
|
47
|
+
public_suffix (5.0.5)
|
43
48
|
racc (1.7.3)
|
44
49
|
rainbow (3.1.1)
|
45
50
|
rake (13.2.1)
|
@@ -81,6 +86,7 @@ PLATFORMS
|
|
81
86
|
|
82
87
|
DEPENDENCIES
|
83
88
|
factory_bot (~> 6.4)
|
89
|
+
json-schema (~> 4.3)
|
84
90
|
pry (~> 0.14.2)
|
85
91
|
rake (~> 13.0)
|
86
92
|
rspec (~> 3.0)
|
data/README.md
CHANGED
@@ -20,9 +20,10 @@ LineItem = Scheming.object do
|
|
20
20
|
attribute :taxable, :bool
|
21
21
|
attribute :price, Float
|
22
22
|
|
23
|
-
optional
|
24
|
-
|
23
|
+
tag(:optional)
|
25
24
|
attribute :desc, Nullable(String)
|
25
|
+
|
26
|
+
tag(:optional)
|
26
27
|
attribute :item_type, Enum('entertainment', 'staple')
|
27
28
|
end
|
28
29
|
|
@@ -57,15 +58,15 @@ Scheming::Schema.json(Receipt)
|
|
57
58
|
{ type: 'null' }
|
58
59
|
]
|
59
60
|
},
|
60
|
-
price: { type: '
|
61
|
+
price: { type: 'number' },
|
61
62
|
item_type: {
|
62
63
|
type: 'string',
|
63
|
-
enum:
|
64
|
+
enum: ['intertainment', 'staple']
|
64
65
|
}
|
65
66
|
}
|
66
67
|
}
|
67
68
|
},
|
68
|
-
total: { type: '
|
69
|
+
total: { type: 'number' }
|
69
70
|
}
|
70
71
|
}
|
71
72
|
```
|
@@ -7,7 +7,7 @@ class Scheming::DSL::DataBuilder
|
|
7
7
|
def initialize(builder = Scheming::Attribute::ListBuilder.new)
|
8
8
|
@builder = builder
|
9
9
|
@resolver = Scheming::DSL::TypeResolver
|
10
|
-
@
|
10
|
+
@tagging = Scheming::DSL::Tagging.new
|
11
11
|
end
|
12
12
|
|
13
13
|
# @param field_name [Symbol]
|
@@ -18,14 +18,17 @@ class Scheming::DSL::DataBuilder
|
|
18
18
|
@builder = @builder.attribute(
|
19
19
|
field_name,
|
20
20
|
type: @resolver.resolve(type_spec),
|
21
|
-
|
21
|
+
**@tagging.attribute_params
|
22
22
|
)
|
23
|
+
@tagging.reset!
|
23
24
|
nil
|
24
25
|
end
|
25
26
|
|
26
|
-
#
|
27
|
-
|
28
|
-
|
27
|
+
# @param name [Symbol]
|
28
|
+
# @param args [Hash<Symbol, Object>]
|
29
|
+
def tag(name, **args)
|
30
|
+
@tagging.tag!(name, args)
|
31
|
+
nil
|
29
32
|
end
|
30
33
|
|
31
34
|
# @return [Class]
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# = Type Resolver
|
4
|
+
class Scheming::DSL::Tagging
|
5
|
+
# = Attribute Tag
|
6
|
+
#
|
7
|
+
# Simple representation of a concept
|
8
|
+
# that can be used to aid in the
|
9
|
+
# creation of an [Scheming::Attribute]
|
10
|
+
#
|
11
|
+
class Tag
|
12
|
+
# @param name [Symbo]
|
13
|
+
# @data [Hash<Symbol, Object>]
|
14
|
+
def initialize(name, data)
|
15
|
+
@name = name
|
16
|
+
@data = data
|
17
|
+
end
|
18
|
+
end
|
19
|
+
private_constant :Tag
|
20
|
+
|
21
|
+
def initialize
|
22
|
+
# @type [Hash<Symbol, Tag>]
|
23
|
+
@tags = {}
|
24
|
+
end
|
25
|
+
|
26
|
+
# @return [void]
|
27
|
+
def reset!
|
28
|
+
@tags.clear
|
29
|
+
nil
|
30
|
+
end
|
31
|
+
|
32
|
+
# @param taglist [Hash<Symbol, Object>]
|
33
|
+
# @param name [Symbol]
|
34
|
+
# @return [Tag]
|
35
|
+
def tag!(name, data)
|
36
|
+
@tags[name] = Tag.new(name, data)
|
37
|
+
end
|
38
|
+
|
39
|
+
def attribute_params
|
40
|
+
{
|
41
|
+
is_required: missing?(:optional)
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def missing?(name) = !has?(name)
|
46
|
+
def has?(name) = @tags.key?(name)
|
47
|
+
end
|
data/lib/scheming/dsl.rb
CHANGED
data/lib/scheming/schema/json.rb
CHANGED
@@ -6,7 +6,7 @@ module Scheming::Schema
|
|
6
6
|
module Constants
|
7
7
|
NULL = { type: 'null' }.freeze
|
8
8
|
INTEGER = { type: 'integer' }.freeze
|
9
|
-
FLOAT = { type: '
|
9
|
+
FLOAT = { type: 'number' }.freeze
|
10
10
|
STRING = { type: 'string' }.freeze
|
11
11
|
BOOLEAN = { type: 'boolean' }.freeze
|
12
12
|
end
|
@@ -68,7 +68,7 @@ module Scheming::Schema
|
|
68
68
|
|
69
69
|
refine Scheming::Type::Enum do
|
70
70
|
def schema
|
71
|
-
type.schema.merge(enum: values).freeze
|
71
|
+
type.schema.merge(enum: values.to_a.freeze).freeze
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
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.4.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-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ergonomic Data Design for the Masses
|
14
14
|
email:
|
@@ -32,6 +32,7 @@ files:
|
|
32
32
|
- lib/scheming/dsl.rb
|
33
33
|
- lib/scheming/dsl/data_builder.rb
|
34
34
|
- lib/scheming/dsl/object_type_def.rb
|
35
|
+
- lib/scheming/dsl/tagging.rb
|
35
36
|
- lib/scheming/dsl/type_resolver.rb
|
36
37
|
- lib/scheming/dsl/type_specs.rb
|
37
38
|
- lib/scheming/schema.rb
|
@@ -39,7 +40,7 @@ files:
|
|
39
40
|
- lib/scheming/type.rb
|
40
41
|
- lib/scheming/version.rb
|
41
42
|
- sig/scheming.rbs
|
42
|
-
homepage:
|
43
|
+
homepage: https://github.com/benfalk/scheming
|
43
44
|
licenses:
|
44
45
|
- MIT
|
45
46
|
metadata:
|