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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a71514dd3a8b1f9640a40adf0bbfd928cab9abe7b6981fad8ac0e25a1c7add01
4
- data.tar.gz: edad4ab18d9c22efebbdc39b9a7c74d451e9a41b9b85892a743bb0dc726301b2
3
+ metadata.gz: ff00e122a5534ba54406fa8ffbf47b936fa564fdb26fd601299b0a8f508ebff1
4
+ data.tar.gz: e45e06743f0bc67d1176b7d6489127e476fd8e80e3ae67a2787d544cda7213df
5
5
  SHA512:
6
- metadata.gz: daaff46c5331a1dd747fadfd50701f497225d05104d443dce75c0b8d244445943cea917e5d2ad39a2daf2fbe271ea08edd0930ac351a12dd1ff552c05b6fb590
7
- data.tar.gz: 28f7756667869ff46d076f74dc89849d65a5fc3609c2c472d85f02cfe16143c74936ac7d16bb2d577650b53df159d9402d34926999f6e8aa3808d721dec2afc9
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
- attribute :type, Enum('entertainment', 'staple')
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 desc price item_type],
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: %w[entertainment staple].to_set
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
- type = @resolver.resolve(type_spec)
18
- @builder = @builder.attribute(field_name, type:)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Scheming
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
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.1.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: []