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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 451f27d06fabf944c809fe98c5942634ebb0578c054a70b82dcbcd831cafc25f
4
- data.tar.gz: 661475b942ccf70af3ae9660fd812c335b4d1b5ee37bf43b05b761505cd5be1c
3
+ metadata.gz: 2b4b40b55df024e10d5e33e9a6b436c5c037750a4026f2c4ccedb28f27a7c75a
4
+ data.tar.gz: 92ddb3043c1fe5cd63a319b19150bf8af73d8302502905d1be5fc8eed616db75
5
5
  SHA512:
6
- metadata.gz: 270e518392f9702d5640b608b1138d4a8899f4f0fa3cf17a1f1dd22c593a869888dbcc1c405b12113e803d509a81a64b61f6749ee62430c55c49c694e1b9ce0c
7
- data.tar.gz: 8e198d598f009d01e7ed7b1d33f5e243753b626d94822a4d5d889162d23046a7ad934a381b5347fdee0cdaea0a7d4f865429818e2c08dfef422c31ff9ed38a8b
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.partition do |field, _|
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
@@ -1,3 +1,3 @@
1
1
  module BetterValidations
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: better_validations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Petr Bazov