schema-model 0.6.6 → 0.6.7

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: a73780000277f79895caa968d7f1c26419a3202f471623df279b66b07e5fc9ae
4
- data.tar.gz: efaab2f375e9bcf1abf32997e2e457e6fd9abd2691bb9b58e20a04816255a612
3
+ metadata.gz: 2d01f7e858fed4dffa69a85156b6327fb3c4e67467c50f578ca3682dc928e7c4
4
+ data.tar.gz: aac56417163c73a92d429d261b0ad282b022af212563929ba8e195ff2528d521
5
5
  SHA512:
6
- metadata.gz: 440393dc4b00e289aa867435ad1ef057bb9a5d964a834d2175b2de3699a0b3555ad422bc3db914736323c25f6871b0161c003228d3b6ab783b6bbccc8c1aeef1
7
- data.tar.gz: 61379e61fe8ba8aefcec1a4f4aed9bca1155e09ef0d6bb17a68f8f7270e08c0824d17bb40cf42be56d21966401ca5b3ea550b430b531a873a0c6bfd1abdc26e9
6
+ metadata.gz: 52f91fc3c2c59f28a8a196abe8655085f81cd13ffaf30942475e2f07302ba0316fe4c7ba2fdcd8777fafe0655b81c6f40751c57c555a14ebbbdd23c464cdbdd7
7
+ data.tar.gz: d55fe9477de36a8d00f84820ea2c592311bb75937d9b227b95ee14091d95e9fb16f0d06675e360c731590acdff420380db61110f05ffa3f6fb7fb1d464769c02
@@ -10,11 +10,40 @@ module Schema
10
10
  base.schema_include OverrideParsingErrors
11
11
  end
12
12
 
13
+ def valid_model!
14
+ unless valid?
15
+ raise ValidationException.new(
16
+ "invalid values for attributes #{errors.map(&:attribute).join(', ')}",
17
+ self,
18
+ errors
19
+ )
20
+ end
21
+ end
22
+
23
+ def valid!
24
+ parsed!
25
+ valid_model!
26
+ end
27
+
13
28
  # no-doc
14
29
  module OverrideParsingErrors
15
30
  def parsing_errors
16
31
  @parsing_errors ||= ActiveModel::Errors.new(self)
17
32
  end
33
+
34
+ def parsed?
35
+ parsing_errors.empty?
36
+ end
37
+
38
+ def parsed!
39
+ unless parsed?
40
+ raise ParsingException.new(
41
+ "schema parsing failed for attributes #{parsing_errors.errors.map(&:attribute).join(', ')}",
42
+ self,
43
+ parsing_errors
44
+ )
45
+ end
46
+ end
18
47
  end
19
48
  end
20
49
  end
data/lib/schema-model.rb CHANGED
@@ -4,6 +4,19 @@ autoload :SchemaValidator, 'schema_validator'
4
4
 
5
5
  # Schema is a series of tools for transforming data into models
6
6
  module Schema
7
+ class SchemaException < StandardError
8
+ attr_reader :schema,
9
+ :errors
10
+
11
+ def initialize(msg, schema, errors)
12
+ super(msg)
13
+ @schema = schema
14
+ @errors = errors
15
+ end
16
+ end
17
+ class ParsingException < SchemaException; end
18
+ class ValidationException < SchemaException; end
19
+
7
20
  autoload :ActiveModelValidations, 'schema/active_model_validations'
8
21
  autoload :All, 'schema/all'
9
22
  autoload :ArrayHeaders, 'schema/array_headers'
data/schema-model.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'schema-model'
5
- s.version = '0.6.6'
5
+ s.version = '0.6.7'
6
6
  s.licenses = ['MIT']
7
7
  s.summary = 'Schema Model'
8
8
  s.description = 'Easy way to create models from payloads'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schema-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.6
4
+ version: 0.6.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Doug Youch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-25 00:00:00.000000000 Z
11
+ date: 2022-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: inheritance-helper