better_validations 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/better_validations/errors.rb +12 -4
- data/lib/better_validations/version.rb +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: 2b4b40b55df024e10d5e33e9a6b436c5c037750a4026f2c4ccedb28f27a7c75a
|
4
|
+
data.tar.gz: 92ddb3043c1fe5cd63a319b19150bf8af73d8302502905d1be5fc8eed616db75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ffc09214a899be22ee6c4396757b1a63f12c5140609457a2380087c9f806d0568288456b57c18ffb6213e123d47a306823dbcad48f45505c3ba3b1577c0eb81
|
7
|
+
data.tar.gz: 8ae381db15d07eabba0fbd06bd9594fd976ef2459d6bf8ed0e404f4331e64a813826cc0fc84276f39b11eb9cf7d5fd923a03d62cd90e190be8e36adf2c10f55b
|
@@ -24,10 +24,7 @@ module BetterValidations::Errors
|
|
24
24
|
|
25
25
|
# Split errors to field errors and nested objects errors.
|
26
26
|
# A dot symbol means that the error is happened with a nested object.
|
27
|
-
nested_messages, field_messages = @messages
|
28
|
-
base_field_name = field.to_s.split('.').first.to_sym
|
29
|
-
@base.class.reflect_on_association(base_field_name)
|
30
|
-
end.map(&:to_h)
|
27
|
+
nested_messages, field_messages = split_messages(@messages)
|
31
28
|
|
32
29
|
if wrap_attributes_to.present? && field_messages.present?
|
33
30
|
field_messages = { wrap_attributes_to => field_messages }
|
@@ -42,6 +39,17 @@ module BetterValidations::Errors
|
|
42
39
|
)
|
43
40
|
end
|
44
41
|
|
42
|
+
def split_messages(messages)
|
43
|
+
if @base.class.respond_to?(:reflect_on_association)
|
44
|
+
return messages.partition do |field, _|
|
45
|
+
base_field_name = field.to_s.split('.').first.to_sym
|
46
|
+
@base.class.reflect_on_association(base_field_name)
|
47
|
+
end.map(&:to_h)
|
48
|
+
end
|
49
|
+
|
50
|
+
messages.partition { |field, _| field.include?('.') }.map(&:to_h)
|
51
|
+
end
|
52
|
+
|
45
53
|
# Converts nested messages to detailed structure with nested objects
|
46
54
|
def parse_nested_messages(nested_messages, wrap_attributes_to)
|
47
55
|
# Get names of all relations with errors
|