jimmy 2.0.2 → 2.0.3

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: 9291e6dbeb83c3460efcb1d9c9c6a26ea984c260436f405491a550158d5bc98e
4
- data.tar.gz: 01cb215623de4558ed11d2a8a3034ce5fe536af7ed7b737f98ff465a4b4b2f12
3
+ metadata.gz: 0d18b13c6558a49c5a5247d5f4cdc0f7d12805b2583b2bab2557d75c29bd823f
4
+ data.tar.gz: bc2e9e773f340dbd4ee3bcf07e6f2eb47fed1d6b5ebb1d4e0f9f195e94ab0d2e
5
5
  SHA512:
6
- metadata.gz: 97be3aa9c5780a9b752759749d35d23eb490c0d88b2b05b10b58336a3d06a09e4f08b47820db2ae76be820e72588ebb88f3b3a2e42bee806c24e8cabedc9cf74
7
- data.tar.gz: a0486165c43307663fb94fa5d557d8213b9b5f32f6c57ea8ad8717af48ff528543752c9823b1c8997bf1ff92acfd7315a79379654b97b9923e906c2337a07440
6
+ metadata.gz: 5133ac0b7b56a3b6b4272a02099e8b1cad2a3b58435cea3b0f0984bf8844128f23a8f6d2c5a4970e0335c134638b768c02befc727bc2ca7f0ac4a08dfc486cc9
7
+ data.tar.gz: d5f0148b17deab8950954970e6a1b6f1964db0144c3121176822b35c140a5a5f7029c95a36a3f62e37366da131a71fc1c9f6687a1cbcf8f529d7e0d90bbe904a
@@ -18,7 +18,7 @@ module Jimmy
18
18
  SchemerFactory.new(*args, **opts).schemer
19
19
  end
20
20
 
21
- # Passes +schema+ to {Schema.new}, unless it is already a {Schema}, in which
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]
@@ -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.string.pattern v },
11
- Range => ->(s, v) { s.number.range v }
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
@@ -129,6 +129,7 @@ require 'jimmy/schema/number'
129
129
  require 'jimmy/schema/object'
130
130
  require 'jimmy/schema/string'
131
131
 
132
+ require 'jimmy/schema/conditions'
132
133
  require 'jimmy/schema/operators'
133
134
  require 'jimmy/schema/json'
134
135
  require 'jimmy/schema/casting'
@@ -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 {JSONSchemer::Schema::Base} that can be used to
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Jimmy
4
- VERSION = '2.0.2'
4
+ VERSION = '2.0.3'
5
5
  end
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.2
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-01 00:00:00.000000000 Z
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