serial_translator 1.0.0 → 1.0.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
  SHA1:
3
- metadata.gz: ddceed208a6817aa8b7484c890d2340ec50ba391
4
- data.tar.gz: f68db01cd4a2e5c0c4a9fadaae0990830a3d6c52
3
+ metadata.gz: 8d27d575ab149486ef5bbc0de313ed02910fc219
4
+ data.tar.gz: 1f451012813d7f174b899854cbe7df20c27d351b
5
5
  SHA512:
6
- metadata.gz: a7412fbf5664d5808690344dd63c58de0633490738e74a2f52cf83a578fc889ce73aa3fb00c15868f10fdccb86feac7f3272998d65ed8e2e56e1476de7b54e4a
7
- data.tar.gz: ccae43bae3f7da4aad8daf684bb2639a5a2fb463201ba17fe9e37e432f15258c711c4667484712573206814a44ee88b5bd2359024d9b7f83846170a0963522ec
6
+ metadata.gz: fb6562608cbf2444e6685dffda92c86a5ffae68ddfa0348f75951dc78a8c5558c1bacdf0f05f36172e7cf06eb04e1143bd26a1562994fcc238f5ce67fd688bb4
7
+ data.tar.gz: 58245bc9e7834be0f6a38dc6dfb7b12901edc1cdac60c435604d3f08fa9b5414d1c1a7416de1900414aeb33171ca1de5ecb71be3b13a0ef96d669a1481aa602d
@@ -1,36 +1,38 @@
1
- class SerialTranslator::SerialTranslatorLengthValidator < ActiveModel::Validations::LengthValidator
2
- def validate_each(record, attribute, _value)
3
- translations = record.__send__("#{attribute}_translations")&.values || []
4
- translations = [nil] if translations.empty?
5
- translations.each do |value|
6
- next if options[:allow_blank] && value.to_s == '' ||
7
- options[:allow_nil] && value.nil?
8
- validate_translation(record, attribute, value)
1
+ module SerialTranslator
2
+ class SerialTranslatorLengthValidator < ActiveModel::Validations::LengthValidator
3
+ def validate_each(record, attribute, _value)
4
+ translations = record.__send__("#{attribute}_translations")&.values || []
5
+ translations = [nil] if translations.empty?
6
+ translations.each do |value|
7
+ next if options[:allow_blank] && value.to_s == '' ||
8
+ options[:allow_nil] && value.nil?
9
+ validate_translation(record, attribute, value)
10
+ end
9
11
  end
10
- end
11
12
 
12
- # this is ActiveModel::Validations::LengthValidator#validate_each,
13
- # only extended with more interpolation args in error_options
14
- def validate_translation(record, attribute, value)
15
- value_length = value.respond_to?(:length) ? value.length : value.to_s.length
16
- error_options = options.except(*RESERVED_OPTIONS)
13
+ # this is ActiveModel::Validations::LengthValidator#validate_each,
14
+ # only extended with more interpolation args in error_options
15
+ def validate_translation(record, attribute, value)
16
+ value_length = value.respond_to?(:length) ? value.length : value.to_s.length
17
+ error_options = options.except(*RESERVED_OPTIONS)
17
18
 
18
- CHECKS.each do |key, validity_check|
19
- next unless check_value = options[key]
19
+ CHECKS.each do |key, validity_check|
20
+ next unless check_value = options[key]
20
21
 
21
- if !value.nil? || skip_nil_check?(key)
22
- next if value_length.send(validity_check, check_value)
23
- end
22
+ if !value.nil? || skip_nil_check?(key)
23
+ next if value_length.send(validity_check, check_value)
24
+ end
24
25
 
25
- error_options.merge!(count: check_value, actual_length: value_length)
26
- key == :minimum && error_options[:difference] = check_value - value_length
27
- key == :maximum && error_options[:difference] = value_length - check_value
26
+ error_options.merge!(count: check_value, actual_length: value_length)
27
+ key == :minimum && error_options[:difference] = check_value - value_length
28
+ key == :maximum && error_options[:difference] = value_length - check_value
28
29
 
29
- default_message = options[MESSAGES[key]]
30
- error_options[:message] ||= default_message if default_message
31
- record.errors.add(attribute, MESSAGES[key], error_options)
30
+ default_message = options[MESSAGES[key]]
31
+ error_options[:message] ||= default_message if default_message
32
+ record.errors.add(attribute, MESSAGES[key], error_options)
33
+ end
32
34
  end
33
- end
34
35
 
35
- def kind; :length end
36
+ def kind; :length end
37
+ end
36
38
  end
@@ -1,9 +1,11 @@
1
- class SerialTranslator::SerialTranslatorPresenceValidator < ActiveModel::Validations::PresenceValidator
2
- def validate_each(record, attribute, _value)
3
- translations = record.__send__("#{attribute}_translations") || {}
4
- return if translations.values.any?(&:present?)
5
- record.errors.add_on_blank(attribute, options)
6
- end
1
+ module SerialTranslator
2
+ class SerialTranslatorPresenceValidator < ActiveModel::Validations::PresenceValidator
3
+ def validate_each(record, attribute, _value)
4
+ translations = record.__send__("#{attribute}_translations") || {}
5
+ return if translations.values.any?(&:present?)
6
+ record.errors.add_on_blank(attribute, options)
7
+ end
7
8
 
8
- def kind; :presence end
9
+ def kind; :presence end
10
+ end
9
11
  end
@@ -1,3 +1,3 @@
1
1
  module SerialTranslator
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serial_translator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - betterplace development team