Module: FirstLevelObjectValidations

Extended by:
ActiveSupport::Concern
Included in:
Concept::Base
Defined in:
app/concerns/first_level_object_validations.rb

Overview

Validations for both concepts and labels

Instance Method Summary collapse

Instance Method Details

#distinct_versionsObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/concerns/first_level_object_validations.rb', line 10

def distinct_versions
  query = self.class.by_origin(origin)
  existing_total = query.count
  if existing_total >= 2
    errors.add :base, I18n.t('txt.models.concept.version_error', origin: origin)
  elsif existing_total == 1
    unless (query.published.count == 0 and published?) or
           (query.published.count == 1 and not published?)
      errors.add :base, I18n.t('txt.models.concept.version_error', origin: origin)
    end
  end
end