Class: Dsu::Validators::DescriptionValidator

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
lib/dsu/validators/description_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/dsu/validators/description_validator.rb', line 6

def validate(record)
  description = record.description

  if description.blank?
    record.errors.add(:description, :blank)
    return
  end

  unless description.is_a?(String)
    # TODO: I18n.
    record.errors.add(:description, 'is the wrong object type. ' \
                                    "\"String\" was expected, but \"#{description.class}\" was received.")
    return
  end

  validate_description record
end