Sha256: bd9370fe03e72da6f05f69c43f6de659ca51f685e823743df58acd7c733fe7cc

Contents?: true

Size: 654 Bytes

Versions: 8

Compression:

Stored size: 654 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

8 entries across 8 versions & 1 rubygems

Version Path
simple_model_translations-0.2.3 lib/simple_model_translations/validations.rb
simple_model_translations-0.2.2 lib/simple_model_translations/validations.rb
simple_model_translations-0.2.1 lib/simple_model_translations/validations.rb
simple_model_translations-0.2.0 lib/simple_model_translations/validations.rb
simple_model_translations-0.1.9 lib/simple_model_translations/validations.rb
simple_model_translations-0.1.8 lib/simple_model_translations/validations.rb
simple_model_translations-0.1.7 lib/simple_model_translations/validations.rb
simple_model_translations-0.1.6 lib/simple_model_translations/validations.rb