nxt_schema 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '09685f892e03e96e13235c9f5d98c78ddbacd8118a47062c3a4417530cd2a3b0'
4
- data.tar.gz: ec1b647208395d39dc5f61639dcfdfa1ea65caadfa9cd9011414ed9a5a5d9430
3
+ metadata.gz: cad6184f1a5fa47bc5991c5b6b31885d2afc9878e45b1e07a66752f3c7083c73
4
+ data.tar.gz: 8ad13387193ae20005ace29aae75f62ffe251ceaf43209abd85c2b8df6d832eb
5
5
  SHA512:
6
- metadata.gz: 56489e75d59dc6f21f8237fcebc14236113c2e14cb47adb986989f819d0937353b1dd37763b522737923e3a87966eda2bf339f42055383fc8d174d536f1d32e5
7
- data.tar.gz: 1f595737e27ff2c874c807b2339eee3781799a64cac27bd3724642898db6200ec60279edd72b50f100d3a52ff4f8ef155e97392b8738186258d8fd93dbdd65b0
6
+ metadata.gz: 5e2d1ba3e0543713e04ba8432b55482fb8e73684b6bcc7b5040e7a9b2d24ddbd07b512bb9fecd0aa2e543da924de4e13195325a72c5b84bab93b540aa5a590b6
7
+ data.tar.gz: 85f3476e6de7ae21ae578f0c3ac0c6f40b367016d092937d0d107f97a0580e2caaf9b1500d2f11a522597633cfc56b42f427964e8326744abafdf77f18b8a5d4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nxt_schema (0.1.0)
4
+ nxt_schema (0.1.1)
5
5
  activesupport
6
6
  dry-types
7
7
  nxt_registry
@@ -9,7 +9,7 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activesupport (6.0.2.1)
12
+ activesupport (6.0.2.2)
13
13
  concurrent-ruby (~> 1.0, >= 1.0.2)
14
14
  i18n (>= 0.7, < 2)
15
15
  minitest (~> 5.1)
@@ -18,7 +18,7 @@ GEM
18
18
  coderay (1.1.2)
19
19
  concurrent-ruby (1.1.6)
20
20
  diff-lcs (1.3)
21
- dry-configurable (0.11.2)
21
+ dry-configurable (0.11.5)
22
22
  concurrent-ruby (~> 1.0)
23
23
  dry-core (~> 0.4, >= 0.4.7)
24
24
  dry-equalizer (~> 0.2)
@@ -33,7 +33,7 @@ GEM
33
33
  concurrent-ruby (~> 1.0)
34
34
  dry-core (~> 0.2)
35
35
  dry-equalizer (~> 0.2)
36
- dry-types (1.3.1)
36
+ dry-types (1.4.0)
37
37
  concurrent-ruby (~> 1.0)
38
38
  dry-container (~> 0.3)
39
39
  dry-core (~> 0.4, >= 0.4.4)
@@ -47,7 +47,7 @@ GEM
47
47
  hirb (>= 0.6.0)
48
48
  method_source (0.9.2)
49
49
  minitest (5.14.0)
50
- nxt_registry (0.1.4)
50
+ nxt_registry (0.1.5)
51
51
  activesupport
52
52
  pry (0.12.2)
53
53
  coderay (~> 1.1.0)
@@ -69,7 +69,7 @@ GEM
69
69
  thread_safe (0.3.6)
70
70
  tzinfo (1.2.6)
71
71
  thread_safe (~> 0.1)
72
- zeitwerk (2.2.2)
72
+ zeitwerk (2.3.0)
73
73
 
74
74
  PLATFORMS
75
75
  ruby
data/README.md CHANGED
@@ -29,6 +29,13 @@ schema = NxtSchema.root(:company) do
29
29
  requires(:street, :String)
30
30
  requires(:street_number, :Integer)
31
31
  end
32
+
33
+ # Use nodes to create an array of typed nodes
34
+ # The following simple means an array of strings
35
+ nodes(:products) do
36
+ node(:product, :String)
37
+ end
38
+
32
39
 
33
40
  nodes(:employees) do
34
41
  hash(:employee) do
@@ -367,8 +374,13 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERN
367
374
 
368
375
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
369
376
 
370
- # TODO:
377
+ ### TODO:
371
378
 
379
+ - Conditionally required keys:
380
+ required bool => required
381
+ required conditionally => condition applies => required
382
+ required conditionally => condition does not apply => not allowed
383
+
372
384
  - Explain the difference between array nodes and typed array nodes
373
385
  - Should we translate coercion errors as well?
374
386
  - Test the different scenarios of merging schemas array, hash, ...
@@ -1,6 +1,6 @@
1
1
  en:
2
- required_key_missing: "Required key :%{key} is missing in %{target}"
3
- additional_keys_detected: "Additional keys %{keys} not allowed in %{target}"
2
+ required_key_missing: "Required key :%{key} is missing"
3
+ additional_keys_detected: "Additional keys %{keys} not allowed"
4
4
  attribute: "%{attribute} has invalid %{attribute_name} attribute of %{value}"
5
5
  equality: "%{actual} does not equal %{expected}"
6
6
  excludes: "%{value} cannot contain %{target}"
@@ -13,3 +13,4 @@ en:
13
13
  less_than_or_equal: "%{value} must be less than or equal to %{threshold}"
14
14
  pattern: "%{value} must match pattern %{pattern}"
15
15
  query: "%{value}.%{query} was %{actual} and must be true"
16
+ emptiness: "%{value} cannot not be empty"
@@ -84,19 +84,17 @@ module NxtSchema
84
84
  self
85
85
  end
86
86
 
87
- def optional(optional_value, &block)
87
+ def optional(optional_value = nil, &block)
88
88
  raise ArgumentError, 'Optional nodes can only exist within schemas' unless parent.is_a?(NxtSchema::Node::Schema)
89
89
 
90
- options.merge!(optional: optional_value)
91
- evaluate_block(block) if block_given?
90
+ options.merge!(optional: optional_value || block)
92
91
  self
93
92
  end
94
93
 
95
- def presence(presence_value, &block)
94
+ def presence(presence_value = nil, &block)
96
95
  raise ArgumentError, 'Present nodes can only exist within schemas' unless parent.is_a?(NxtSchema::Node::Schema)
97
96
 
98
- options.merge!(presence: presence_value)
99
- evaluate_block(block) if block_given?
97
+ options.merge!(presence: presence_value || block)
100
98
  self
101
99
  end
102
100
 
@@ -26,6 +26,11 @@ module NxtSchema
26
26
 
27
27
  current_node_store = {}
28
28
 
29
+ # if value.empty?
30
+ # message = ErrorMessages.resolve(locale, :emptiness, value: value)
31
+ # add_error(message)
32
+ # end
33
+
29
34
  value.each_with_index do |item, index|
30
35
  item_schema_errors = schema_errors[index] ||= { schema_errors_key => [] }
31
36
  validation_errors[index] ||= { schema_errors_key => [] }
@@ -36,7 +41,6 @@ module NxtSchema
36
41
  current_node.apply(item, parent_node: self, context: context)
37
42
  value_store[index] = current_node.value
38
43
 
39
- # TODO: Extract method here
40
44
  unless current_node.schema_errors?
41
45
  current_node_store.each do |node_name, node|
42
46
  node.schema_errors = { }
@@ -1,3 +1,3 @@
1
1
  module NxtSchema
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/nxt_schema.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require "nxt_schema/version"
2
- require "pry"
3
2
  require "active_support/all"
4
3
  require 'dry-types'
5
4
  require 'nxt_registry'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nxt_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Robecke
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-20 00:00:00.000000000 Z
11
+ date: 2020-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport