class CharacterValidator

Public Instance Methods

validate_each(record, attribute, values) click to toggle source
# File lib/thingtank/validators.rb, line 61
def validate_each(record, attribute, values)
  case values
  when NilClass
    return nil
  when Array
    values.each do |value|
      validate_single_character(record, attribute, value, options)
    end
  else
    validate_single_character(record, attribute, values, options)
  end
end
validate_single_character(record, attribute, values, options) click to toggle source
# File lib/thingtank/validators.rb, line 41
def validate_single_character(record, attribute, values, options)
  if options[:in] # validates :hosting_account, :character => [HostingAccount, ...]
    valid = false
    options[:in].each do |character|
      character = character.new(values)
      if character.valid?
        valid = true
      end
    end
    unless valid
      record.errors.add attribute, "invalid character is #{values.inspect}, should be one of #{options[:in].join(', ')}"
    end
  else
    character = options[:with].new(values)
    unless character.valid?
      record.errors.add attribute, character.errors.messages
    end
  end
end