Sha256: 68078bb5a491b5de3da6f0e13b70821da6df4b3a73cd38c41e9417f3ae4eb624

Contents?: true

Size: 597 Bytes

Versions: 5

Compression:

Stored size: 597 Bytes

Contents

module SimpleModelTranslations
  module Validations
    class TranslationsValidator < ::ActiveModel::Validator
      def validate(record)
        Array.wrap(options[:locales]).each do |locale|
          unless record.translation_helper.find_translation_by_locale(locale)
            record.errors.add(:translations, "miss #{locale} translation")
          end
        end
      end
    end

    def validate_translations(*locales)
      validates_with TranslationsValidator, :locales => locales
    end
    
    def validate_translation(locale)
      validate_translations locale
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
simple_model_translations-0.2.8 lib/simple_model_translations/validations.rb
simple_model_translations-0.2.7 lib/simple_model_translations/validations.rb
simple_model_translations-0.2.6 lib/simple_model_translations/validations.rb
simple_model_translations-0.2.5 lib/simple_model_translations/validations.rb
simple_model_translations-0.2.4 lib/simple_model_translations/validations.rb