jimmy 2.0.2 → 2.0.3
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/lib/jimmy.rb +1 -1
- data/lib/jimmy/declaration.rb +3 -1
- data/lib/jimmy/declaration/casting.rb +2 -2
- data/lib/jimmy/declaration/conditions.rb +18 -0
- data/lib/jimmy/schema.rb +1 -0
- data/lib/jimmy/schema/conditions.rb +19 -0
- data/lib/jimmy/schemer_factory.rb +1 -1
- data/lib/jimmy/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d18b13c6558a49c5a5247d5f4cdc0f7d12805b2583b2bab2557d75c29bd823f
|
4
|
+
data.tar.gz: bc2e9e773f340dbd4ee3bcf07e6f2eb47fed1d6b5ebb1d4e0f9f195e94ab0d2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5133ac0b7b56a3b6b4272a02099e8b1cad2a3b58435cea3b0f0984bf8844128f23a8f6d2c5a4970e0335c134638b768c02befc727bc2ca7f0ac4a08dfc486cc9
|
7
|
+
data.tar.gz: d5f0148b17deab8950954970e6a1b6f1964db0144c3121176822b35c140a5a5f7029c95a36a3f62e37366da131a71fc1c9f6687a1cbcf8f529d7e0d90bbe904a
|
data/lib/jimmy.rb
CHANGED
@@ -18,7 +18,7 @@ module Jimmy
|
|
18
18
|
SchemerFactory.new(*args, **opts).schemer
|
19
19
|
end
|
20
20
|
|
21
|
-
# Passes +schema+ to
|
21
|
+
# Passes +schema+ to +Schema.new+, unless it is already a {Schema}, in which
|
22
22
|
# case it is returned unmodified.
|
23
23
|
# @param [Schema, Object] schema
|
24
24
|
# @return [Schema]
|
data/lib/jimmy/declaration.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'jimmy/declaration/composites'
|
4
|
+
require 'jimmy/declaration/conditions'
|
4
5
|
require 'jimmy/declaration/number'
|
5
6
|
require 'jimmy/declaration/object'
|
6
7
|
require 'jimmy/declaration/string'
|
@@ -60,9 +61,10 @@ module Jimmy
|
|
60
61
|
end
|
61
62
|
|
62
63
|
# Set an enum value for the schema.
|
63
|
-
# @param [Array] allowed_values The allowed values in the enum.
|
64
|
+
# @param [Array, Set] allowed_values The allowed values in the enum.
|
64
65
|
# @return [self] self, for chaining
|
65
66
|
def enum(allowed_values)
|
67
|
+
allowed_values = allowed_values.to_a if allowed_values.is_a? Set
|
66
68
|
assert_array allowed_values, minimum: 1, unique: true
|
67
69
|
set enum: allowed_values
|
68
70
|
end
|
@@ -7,8 +7,8 @@ module Jimmy
|
|
7
7
|
CASTS = {
|
8
8
|
TrueClass => ->(s, _) { s },
|
9
9
|
FalseClass => ->(s, _) { s.nothing },
|
10
|
-
Regexp => ->(s, v) { s.
|
11
|
-
Range => ->(s, v) { s.
|
10
|
+
Regexp => ->(s, v) { s.pattern v },
|
11
|
+
Range => ->(s, v) { s.range v }
|
12
12
|
}.freeze
|
13
13
|
|
14
14
|
CASTABLE_CLASSES = CASTS.keys.freeze
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jimmy
|
4
|
+
module Declaration
|
5
|
+
# Define the schema that determines whether the +then+ or +else+ schemas
|
6
|
+
# must be valid.
|
7
|
+
# @param schema [Schema] The +if+ schema.
|
8
|
+
# @param then_schema [Schema] The +then+ schema.
|
9
|
+
# @param else_schema [Schema] The +else+ schema.
|
10
|
+
# @return [self] self, for chaining
|
11
|
+
def if(schema, then_schema = nil, else_schema = nil)
|
12
|
+
set(if: cast_schema(schema)).tap do |s|
|
13
|
+
s.then then_schema unless then_schema.nil?
|
14
|
+
s.else else_schema unless else_schema.nil?
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/jimmy/schema.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jimmy
|
4
|
+
class Schema
|
5
|
+
# Define the schema that must be valid if the +if+ schema is valid.
|
6
|
+
# @param schema [Jimmy::Schema] The +then+ schema.
|
7
|
+
# @return [self] self, for chaining
|
8
|
+
def then(schema)
|
9
|
+
set then: cast_schema(schema)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Define the schema that must be valid if the +if+ schema is not valid.
|
13
|
+
# @param schema [Jimmy::Schema] The +else+ schema.
|
14
|
+
# @return [self] self, for chaining
|
15
|
+
def else(schema)
|
16
|
+
set else: cast_schema(schema)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -29,7 +29,7 @@ module Jimmy
|
|
29
29
|
@options[:ref_resolver] = res
|
30
30
|
end
|
31
31
|
|
32
|
-
# Get an instance of
|
32
|
+
# Get an instance of +JSONSchemer::Schema::Base+ that can be used to
|
33
33
|
# validate JSON documents against the given {Schema}.
|
34
34
|
# @return [JSONSchemer::Schema::Base]
|
35
35
|
def schemer
|
data/lib/jimmy/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jimmy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Neil E. Pearson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-06-
|
11
|
+
date: 2020-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Jimmy the Gem
|
14
14
|
email:
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- lib/jimmy/declaration/assertion.rb
|
37
37
|
- lib/jimmy/declaration/casting.rb
|
38
38
|
- lib/jimmy/declaration/composites.rb
|
39
|
+
- lib/jimmy/declaration/conditions.rb
|
39
40
|
- lib/jimmy/declaration/number.rb
|
40
41
|
- lib/jimmy/declaration/object.rb
|
41
42
|
- lib/jimmy/declaration/string.rb
|
@@ -55,6 +56,7 @@ files:
|
|
55
56
|
- lib/jimmy/schema.rb
|
56
57
|
- lib/jimmy/schema/array.rb
|
57
58
|
- lib/jimmy/schema/casting.rb
|
59
|
+
- lib/jimmy/schema/conditions.rb
|
58
60
|
- lib/jimmy/schema/json.rb
|
59
61
|
- lib/jimmy/schema/number.rb
|
60
62
|
- lib/jimmy/schema/object.rb
|