Method: ClassValidator#validate_single_class

Defined in:
lib/thingtank/validators.rb

#validate_single_class(record, attribute, values, options) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/thingtank/validators.rb', line 2

def validate_single_class(record, attribute, values, options)
  if options[:in] # validates :hosting_account, :class => [Hash, String]
    valid = false
    options[:in].each do |klass|
      if values.is_a?(klass)
        valid = true
      end
    end
    unless valid
      record.errors.add attribute, "invalid class is #{values.class.to_s}, should be one of #{options[:in].join(', ')}"
    end
  else # validates :hosting_account, :class => Hash
    unless values.is_a?(options[:with])
      record.errors.add attribute, "invalid class is #{values.class.to_s}, should be #{options[:with]}"
    end
  end
end