Sha256: aa23c41e85f52c3d111c8c8b062523b53057f020da657355bfc5f1b249eca9dd

Contents?: true

Size: 889 Bytes

Versions: 12

Compression:

Stored size: 889 Bytes

Contents

class PropertyValueValidator < ActiveModel::Validator

  def validate(record)
    return true unless record.new_value
    template, rxp = record.template.split('+')
    rxp = template unless rxp
    if validation = Validations[rxp]
      if record.new_value ~! validation
        record.errors[:base] << I18n.t('validation.format')
        return false
      end
    end
    true
  end

private

  Validations = {
      'on_off' => /\A(on)|(off)\Z/i,

      'yes_no' => /\A(yes)|(no)\Z/i,

      'mega_size' => /\A\d+[bBkKmMgG]?\Z/i,

      'mail_name' => /\A[a-z0-9](\s|[a-z0-9])*\Z/i,

      'domain' => /\A[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}\Z/i,

      'param_string' => /\A(\w|\d|\s|\$|@|%|_|-|\.|:)*\Z/i,

      'string' => /\A[a-zA-Z0-9_-]*\Z/i,

      'number' => /\A(\+|-)?\d+\Z/i,

      'percent' => /\A\d+%\Z/i,

      'select_from_enum' => /\A(\+?\w+;?)*\Z/i
  }


end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rmails-0.2.5 app/models/property_value_validator.rb
rmails-0.2.4 app/models/property_value_validator.rb
rmails-0.2.3 app/models/property_value_validator.rb
rmails-0.2.2 app/models/property_value_validator.rb
rmails-0.2.1 app/models/property_value_validator.rb
rmails-0.2.0 app/models/property_value_validator.rb
rmails-0.1.6 app/models/property_value_validator.rb
rmails-0.1.5 app/models/property_value_validator.rb
rmails-0.1.4 app/models/property_value_validator.rb
rmails-0.1.3 app/models/property_value_validator.rb
rmails-0.1.2 app/models/property_value_validator.rb
rmails-0.1.1 app/models/property_value_validator.rb