schema-model 0.6.7 → 0.6.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/schema/associations/schema_creator.rb +1 -1
- data/lib/schema/model.rb +17 -2
- data/schema-model.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d996d080555c7553965069f80fc44c902ef72831635bdab8ae6515883e00334
|
4
|
+
data.tar.gz: da062d6c1a477c63382116961a7a8634cd13444a8a1797c38067d34d44d1faf0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b29a0e7d32895ffe1c941860cb9f1af7efcfa4bc0a82a8ea86956d5c322f5fb1255301ee1702555546cc5d662c4981c2145167c9f453bdb15ce21fd34002ce1d
|
7
|
+
data.tar.gz: 4bac466d153605319ae50dc62a028e42b07ffe93ae589f4ed99dcedd54ade7a899f51acfbef45b35f395f77f8f2450cbcbdf2f57caf6d7afcfa1f75b66f2f22b
|
@@ -20,7 +20,7 @@ module Schema
|
|
20
20
|
def create_schema(base_schema, data, error_name = nil)
|
21
21
|
if data.is_a?(Hash)
|
22
22
|
unless (schema_class = get_schema_class(base_schema, data))
|
23
|
-
add_parsing_error(base_schema, error_name, UNKNOWN)
|
23
|
+
add_parsing_error(base_schema, error_name, UNKNOWN) if base_schema.class.capture_unknown_attributes?
|
24
24
|
return nil
|
25
25
|
end
|
26
26
|
schema = schema_class.from_hash(data)
|
data/lib/schema/model.rb
CHANGED
@@ -25,6 +25,10 @@ module Schema
|
|
25
25
|
|
26
26
|
# no-doc
|
27
27
|
module ClassMethods
|
28
|
+
def self.include(base)
|
29
|
+
base.capture_unknown_attributes = true
|
30
|
+
end
|
31
|
+
|
28
32
|
def schema
|
29
33
|
{}.freeze
|
30
34
|
end
|
@@ -40,10 +44,21 @@ module Schema
|
|
40
44
|
|
41
45
|
def schema_config
|
42
46
|
{
|
43
|
-
schema_includes: []
|
47
|
+
schema_includes: [],
|
48
|
+
capture_unknown_attributes: true
|
44
49
|
}.freeze
|
45
50
|
end
|
46
51
|
|
52
|
+
def capture_unknown_attributes=(v)
|
53
|
+
config = schema_config.dup
|
54
|
+
config[:capture_unknown_attributes] = v
|
55
|
+
redefine_class_method(:schema_config, config.freeze)
|
56
|
+
end
|
57
|
+
|
58
|
+
def capture_unknown_attributes?
|
59
|
+
schema_config[:capture_unknown_attributes]
|
60
|
+
end
|
61
|
+
|
47
62
|
def attribute(name, type, options = {})
|
48
63
|
options[:aliases] = [options[:alias]] if options.key?(:alias)
|
49
64
|
|
@@ -148,7 +163,7 @@ STR
|
|
148
163
|
def update_model_attributes(schema, data)
|
149
164
|
data.each do |key, value|
|
150
165
|
unless schema.key?(key)
|
151
|
-
parsing_errors.add(key, ::Schema::ParsingErrors::UNKNOWN_ATTRIBUTE)
|
166
|
+
parsing_errors.add(key, ::Schema::ParsingErrors::UNKNOWN_ATTRIBUTE) if self.class.capture_unknown_attributes?
|
152
167
|
next
|
153
168
|
end
|
154
169
|
|
data/schema-model.gemspec
CHANGED