Sha256: 70f0aab424b29853bf8d9c77d5c19d107f3ac0f0c66000f1c16e4881094f22a9

Contents?: true

Size: 1.12 KB

Versions: 7

Compression:

Stored size: 1.12 KB

Contents

class PresenceInTenantValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    if value
      if value.class.to_s.index 'ActiveRecord_Associations_CollectionProxy'
        value.each do |dat|
          if record.tenant_id != dat.tenant_id
            record.errors.add(attribute, :not_in_tenant, message: I18n.t('activerecord.errors.models.'+record.model_name.i18n_key.to_s+'.attributes.'+attribute.to_s+'.not_in_tenant', :default => ['activerecord.errors.messages.not_in_tenant'.to_sym]))
            return
          end
        end
      else
        if record.tenant_id != value.tenant_id
          record.errors.add(attribute, :not_in_tenant, message: I18n.t('activerecord.errors.models.'+record.model_name.i18n_key.to_s+'.attributes.'+attribute.to_s+'.not_in_tenant', :default => ['activerecord.errors.messages.not_in_tenant'.to_sym]))
        end
      end
    else
      record.errors.add(attribute, :blank, message: I18n.t('activerecord.errors.models.'+record.model_name.i18n_key.to_s+'.attributes.'+attribute.to_s+'.blank', :default => ['activerecord.errors.messages.blank'.to_sym]))
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
anoubis-1.0.12 app/validators/presence_in_tenant_validator.rb
anoubis-1.0.11 app/validators/presence_in_tenant_validator.rb
anoubis-1.0.10 app/validators/presence_in_tenant_validator.rb
anoubis-1.0.8 app/validators/presence_in_tenant_validator.rb
anoubis-1.0.7 app/validators/presence_in_tenant_validator.rb
anoubis-1.0.1 app/validators/presence_in_tenant_validator.rb
anoubis-1.0.0 app/validators/presence_in_tenant_validator.rb