scheming 0.1.0 → 0.2.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 +21 -0
- data/README.md +7 -4
- data/lib/scheming/dsl/data_builder.rb +11 -2
- data/lib/scheming/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff00e122a5534ba54406fa8ffbf47b936fa564fdb26fd601299b0a8f508ebff1
|
4
|
+
data.tar.gz: e45e06743f0bc67d1176b7d6489127e476fd8e80e3ae67a2787d544cda7213df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2a00a25d768946d55420bbd27a47fe598068f806d438b37930a62455647d65be1f72f5961be55e8e82723befa11713dad504fdebce532d228b521dcc3abc3f3
|
7
|
+
data.tar.gz: dbef726a89b0831591327eb7a23c6686f566f0b8ec790fb58b0b2214615bb7b32419b6267a1edff4418b69dba9794e18e3744e6e816fbeffb20aa41cd5b160b5
|
data/CHANGELOG.md
CHANGED
@@ -3,3 +3,24 @@
|
|
3
3
|
## [0.1.0] - 2024-04-26
|
4
4
|
|
5
5
|
- Initial release
|
6
|
+
|
7
|
+
## [0.2.0] - 2024-05-01
|
8
|
+
|
9
|
+
### Added
|
10
|
+
|
11
|
+
- Support for `optional` fields
|
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
|
+
optional
|
22
|
+
|
23
|
+
attribute :desc, Nullable(String)
|
24
|
+
attribute :item_type, Enum('entertainment', 'staple')
|
25
|
+
end
|
26
|
+
```
|
data/README.md
CHANGED
@@ -18,9 +18,12 @@ LineItem = Scheming.object do
|
|
18
18
|
attribute :id, Integer
|
19
19
|
attribute :name, String
|
20
20
|
attribute :taxable, :bool
|
21
|
-
attribute :desc, Nullable(String)
|
22
21
|
attribute :price, Float
|
23
|
-
|
22
|
+
|
23
|
+
optional
|
24
|
+
|
25
|
+
attribute :desc, Nullable(String)
|
26
|
+
attribute :item_type, Enum('entertainment', 'staple')
|
24
27
|
end
|
25
28
|
|
26
29
|
Receipt = Scheming.object do
|
@@ -43,7 +46,7 @@ Scheming::Schema.json(Receipt)
|
|
43
46
|
items: {
|
44
47
|
type: 'object',
|
45
48
|
additionalProperties: false,
|
46
|
-
required: %i[id name taxable
|
49
|
+
required: %i[id name taxable price],
|
47
50
|
properties: {
|
48
51
|
id: { type: 'integer' },
|
49
52
|
name: { type: 'string' },
|
@@ -57,7 +60,7 @@ Scheming::Schema.json(Receipt)
|
|
57
60
|
price: { type: 'numeric' },
|
58
61
|
item_type: {
|
59
62
|
type: 'string',
|
60
|
-
enum:
|
63
|
+
enum: Set['intertainment', 'staple']
|
61
64
|
}
|
62
65
|
}
|
63
66
|
}
|
@@ -7,6 +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
|
+
@required = true
|
10
11
|
end
|
11
12
|
|
12
13
|
# @param field_name [Symbol]
|
@@ -14,11 +15,19 @@ class Scheming::DSL::DataBuilder
|
|
14
15
|
# @param null [Boolean]
|
15
16
|
# @return [void]
|
16
17
|
def attribute(field_name, type_spec)
|
17
|
-
|
18
|
-
|
18
|
+
@builder = @builder.attribute(
|
19
|
+
field_name,
|
20
|
+
type: @resolver.resolve(type_spec),
|
21
|
+
is_required: @required
|
22
|
+
)
|
19
23
|
nil
|
20
24
|
end
|
21
25
|
|
26
|
+
# Mark all arrtibutes after this as optional
|
27
|
+
def optional
|
28
|
+
@required = false
|
29
|
+
end
|
30
|
+
|
22
31
|
# @return [Class]
|
23
32
|
def build
|
24
33
|
list = @builder.build
|
data/lib/scheming/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scheming
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Falk
|
@@ -43,6 +43,8 @@ homepage:
|
|
43
43
|
licenses:
|
44
44
|
- MIT
|
45
45
|
metadata:
|
46
|
+
source_code_uri: https://github.com/benfalk/scheming
|
47
|
+
changelog_uri: https://raw.githubusercontent.com/benfalk/scheming/main/CHANGELOG.md
|
46
48
|
rubygems_mfa_required: 'true'
|
47
49
|
post_install_message:
|
48
50
|
rdoc_options: []
|