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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2d01f7e858fed4dffa69a85156b6327fb3c4e67467c50f578ca3682dc928e7c4
4
- data.tar.gz: aac56417163c73a92d429d261b0ad282b022af212563929ba8e195ff2528d521
3
+ metadata.gz: 5d996d080555c7553965069f80fc44c902ef72831635bdab8ae6515883e00334
4
+ data.tar.gz: da062d6c1a477c63382116961a7a8634cd13444a8a1797c38067d34d44d1faf0
5
5
  SHA512:
6
- metadata.gz: 52f91fc3c2c59f28a8a196abe8655085f81cd13ffaf30942475e2f07302ba0316fe4c7ba2fdcd8777fafe0655b81c6f40751c57c555a14ebbbdd23c464cdbdd7
7
- data.tar.gz: d55fe9477de36a8d00f84820ea2c592311bb75937d9b227b95ee14091d95e9fb16f0d06675e360c731590acdff420380db61110f05ffa3f6fb7fb1d464769c02
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'schema-model'
5
- s.version = '0.6.7'
5
+ s.version = '0.6.8'
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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schema-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.7
4
+ version: 0.6.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Doug Youch