schema-model 0.3.2 → 0.3.5

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: 2930827fc56c8ef958799e26a4fe5c0e4033449ff61d0e58bbdd107d77dc0f2c
4
- data.tar.gz: 43306799287c8c4edb21e07bf21924f2a6b165bdef2cb934401edb2e0549414d
3
+ metadata.gz: da011575b9914ac318fbb72560445ea592d6a90ae38cb585938875545623e0e1
4
+ data.tar.gz: 79a01b51f835ce95c06ab76455c6b003195b594320b847ce2c86f65654e7ea23
5
5
  SHA512:
6
- metadata.gz: 97ac444c3f460681e01b529f6d5e872f426e3b3ef44097a9c6492168f2175dc403b3f98318e72f1c79702440bbb7b2d45c9158591896e71c2bd94f0b6f4ece8b
7
- data.tar.gz: 4a090a51203d1c97c75946ce6f297252e31a1137b7e7637821d148c702ba148f1d13e4de5b0c5c5843e2dbbf4b314a3688d1b7d7ced8e291050f8eb240964ee7
6
+ metadata.gz: c2ee95f2602f4217373b1f65ecbfd8f6f16c39e0cc1d3627f60b34340ba67071b120a336a96017ff2f219a854aca6dcd243fa6dc759a79d223922b10035287f5
7
+ data.tar.gz: 9b3a13a9c2e825a47f76b82f19942703be354d5c8ae912d4f1c2b44e9a5f31f3e9134b6df509531be5113ae75eacdf7a225007cbeead2992404f1b442e302d1a
@@ -24,7 +24,7 @@ module Schema
24
24
  end
25
25
 
26
26
  def dynamic_type_names
27
- dynamic_types.keys
27
+ dynamic_types.keys - [:default]
28
28
  end
29
29
 
30
30
  private
@@ -58,7 +58,13 @@ module Schema
58
58
  name = name.downcase if @ignorecase
59
59
  return base_schema.class.const_get(class_name) if name == type
60
60
  end
61
- nil
61
+ get_default_dynamic_schema_class(base_schema)
62
+ end
63
+
64
+ def get_default_dynamic_schema_class(base_schema)
65
+ return unless (class_name = @types[:default])
66
+
67
+ base_schema.class.const_get(class_name)
62
68
  end
63
69
 
64
70
  def get_dynamic_type(base_schema, data)
@@ -7,7 +7,8 @@ module Schema
7
7
  def parse_array(field_name, parsing_errors, value)
8
8
  case value
9
9
  when ::Array
10
- value
10
+ schema_options = self.class.schema[field_name]
11
+ Array.convert_array_values(self, field_name, parsing_errors, value, schema_options)
11
12
  when String
12
13
  schema_options = self.class.schema[field_name]
13
14
  if (data = Array.parse_string_array(self, field_name, parsing_errors, value, schema_options))
@@ -3,6 +3,20 @@
3
3
  # SchemaValidator validates nested schemas
4
4
  class SchemaValidator < ActiveModel::EachValidator
5
5
  def validate_each(record, attribute, value)
6
- record.errors.add(attribute, options.fetch(:message, :invalid)) if value && !value.valid?
6
+ record.errors.add(attribute, options.fetch(:message, :invalid)) unless valid_schema?(value)
7
+ end
8
+
9
+ private
10
+
11
+ def valid_schema?(value)
12
+ return true unless value
13
+
14
+ if value.is_a?(Array)
15
+ value.all? do |schema|
16
+ !schema || schema.valid?
17
+ end
18
+ else
19
+ value.valid?
20
+ end
7
21
  end
8
22
  end
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.3.2
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Doug Youch