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 +4 -4
- data/lib/schema/active_model_validations.rb +29 -0
- data/lib/schema-model.rb +13 -0
- data/schema-model.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d01f7e858fed4dffa69a85156b6327fb3c4e67467c50f578ca3682dc928e7c4
|
4
|
+
data.tar.gz: aac56417163c73a92d429d261b0ad282b022af212563929ba8e195ff2528d521
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
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.
|
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-
|
11
|
+
date: 2022-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: inheritance-helper
|