scheming 0.3.0 → 0.4.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: bc01781074d4363c7a93440ca775680ad40e390eadf0dd84501501f96aad242f
4
- data.tar.gz: c5356c5b7beb9d74f6489db0d4024973755fc5c2b6a5c015a97d4b21d612191c
3
+ metadata.gz: 9200950b341609a10673661255198aacf8012bdb89b89868d66eed91aa11c395
4
+ data.tar.gz: 175243bb9bd5204b93b5f59f2e0b403163c86ed745a01a23c2e987bc2aab2813
5
5
  SHA512:
6
- metadata.gz: d5ebcaf385cbf2148e37d326c06bd49bd6aa584c9d419096dbb8a7e5f909c191c93b1bc1a294c2a4589c9bf2a9902bf775d73679c440134ebae600ce25e9f110
7
- data.tar.gz: 169ff09cbed7450f5d22754db231e98b5752d98fc00b8dfd2613cb0f0054c59efa24e4b8e86331b32823e76341de46685b8a45abda5416396cdd3b81f8809890
6
+ metadata.gz: 9c83e51b6db0200f0d222250e690696061ecf581bad11e4c5916df828cfef2d6ae01da50349d7a1cdea2097b7a235fe19950c48ec0b11f628522ed734a100e48
7
+ data.tar.gz: b35ebaf5d8d1a30b1538471d153a7da1ed648037c84c89ec2132742bad94fcfee0b0d4744b0c82b3f36de924d30a39579e881a812f4d1ba6fc3bff9c46283415
data/CHANGELOG.md CHANGED
@@ -1,14 +1,14 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [0.1.0] - 2024-04-26
3
+ ## [0.4.0] - 2024-05-02
4
4
 
5
- - Initial release
5
+ ### Breaking Change
6
6
 
7
- ## [0.2.0] - 2024-05-01
8
-
9
- ### Added
10
-
11
- - Support for `optional` fields
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
12
 
13
13
  # Example:
14
14
  ```ruby
@@ -18,12 +18,12 @@
18
18
  attribute :taxable, :bool
19
19
  attribute :price, Float
20
20
 
21
- optional
22
-
21
+ tag(:optional)
23
22
  attribute :desc, Nullable(String)
23
+
24
+ tag(:optional)
24
25
  attribute :item_type, Enum('entertainment', 'staple')
25
26
  end
26
- ```
27
27
 
28
28
  ## [0.3.0] - 2024-05-01
29
29
 
@@ -35,4 +35,29 @@
35
35
 
36
36
  ### Enhancement
37
37
 
38
+ ## [0.2.0] - 2024-05-01
39
+
40
+ ### Added
41
+
42
+ - Support for `optional` fields
43
+
44
+ # Example:
45
+ ```ruby
46
+ LineItem = Scheming.object do
47
+ attribute :id, Integer
48
+ attribute :name, String
49
+ attribute :taxable, :bool
50
+ attribute :price, Float
51
+
52
+ optional
53
+
54
+ attribute :desc, Nullable(String)
55
+ attribute :item_type, Enum('entertainment', 'staple')
56
+ end
57
+ ```
58
+
38
59
  - Ensure all types produce valid JSON Schema
60
+
61
+ ## [0.1.0] - 2024-04-26
62
+
63
+ - Initial release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- scheming (0.3.0)
4
+ scheming (0.4.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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
 
@@ -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
- @required = true
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
- is_required: @required
21
+ **@tagging.attribute_params
22
22
  )
23
+ @tagging.reset!
23
24
  nil
24
25
  end
25
26
 
26
- # Mark all arrtibutes after this as optional
27
- def optional
28
- @required = false
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
@@ -8,6 +8,7 @@
8
8
  # who need to know.
9
9
  #
10
10
  module Scheming::DSL
11
+ require_relative 'dsl/tagging'
11
12
  require_relative 'dsl/type_specs'
12
13
  require_relative 'dsl/data_builder'
13
14
  require_relative 'dsl/object_type_def'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Scheming
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.0'
5
5
  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.3.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-01 00:00:00.000000000 Z
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