Class: CharacterValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- CharacterValidator
- Defined in:
- lib/thingtank/validators.rb
Instance Method Summary collapse
- #validate_each(record, attribute, values) ⇒ Object
- #validate_single_character(record, attribute, values, options) ⇒ Object
Instance Method Details
#validate_each(record, attribute, values) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 |
# 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, ) end else validate_single_character(record, attribute, values, ) end end |
#validate_single_character(record, attribute, values, options) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/thingtank/validators.rb', line 41 def validate_single_character(record, attribute, values, ) if [:in] # validates :hosting_account, :character => [HostingAccount, ...] valid = false [: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 #{[:in].join(', ')}" end else character = [:with].new(values) unless character.valid? record.errors.add attribute, character.errors. end end end |