Class: AdLocalize::Validators::KeyValidator
- Inherits:
-
Object
- Object
- AdLocalize::Validators::KeyValidator
- Defined in:
- lib/ad_localize/validators/key_validator.rb
Instance Method Summary collapse
- #has_warnings?(current_key) ⇒ Boolean
-
#initialize ⇒ KeyValidator
constructor
A new instance of KeyValidator.
Constructor Details
#initialize ⇒ KeyValidator
Returns a new instance of KeyValidator.
5 6 7 |
# File 'lib/ad_localize/validators/key_validator.rb', line 5 def initialize @existing_key_for_label = {} end |
Instance Method Details
#has_warnings?(current_key) ⇒ Boolean
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ad_localize/validators/key_validator.rb', line 9 def has_warnings?(current_key) current_label = current_key.label existing_key = @existing_key_for_label[current_label] has_warnings = false unless existing_key.nil? existing_plural_key = existing_key.label == current_key.label && existing_key.plural? && current_key.singular? existing_singular_key = existing_key.label == current_key.label && existing_key.singular? && current_key.plural? is_same_key = existing_key.same_as?(key: current_key) LOGGER.warn "A plural value already exist for key '#{current_label}'. Remove duplicates." if existing_plural_key LOGGER.warn "A singular value already exist for key '#{current_label}'. Remove duplicates." if existing_singular_key LOGGER.warn "Some values already exist for key '#{current_label}'. Remove duplicates." if is_same_key has_warnings = is_same_key || existing_plural_key || existing_singular_key end @existing_key_for_label[current_label] = current_key has_warnings end |