Sha256: 03418be2eecd3b729d35ddb1b809dfbf27c67877d3341fc02e02355e84060ad6

Contents?: true

Size: 652 Bytes

Versions: 5

Compression:

Stored size: 652 Bytes

Contents

module SimpleModelTranslations
  module Validations
    class TranslationsValidator < ActiveModel::Validator
      def validate(record)
        locales = options[:locales]
        locales = [locales] unless locales.respond_to?(:each)
        locales.each do |locale|
          unless record.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.1.4 lib/simple_model_translations/validations.rb
simple_model_translations-0.1.3 lib/simple_model_translations/validations.rb
simple_model_translations-0.1.2 lib/simple_model_translations/validations.rb
simple_model_translations-0.1.1 lib/simple_model_translations/validations.rb
simple_model_translations-0.1.0 lib/simple_model_translations/validations.rb