Class: Dsu::Validators::VersionValidator

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

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dsu/validators/version_validator.rb', line 7

def validate(record)
  version = record.version

  if version.nil?
    record.errors.add(:version, 'is nil')
    return
  end

  unless version.is_a?(Integer)
    record.errors.add(:version, 'is the wrong object type. ' \
                                "\"Integer\" was expected, but \"#{version.class}\" was received.")
    nil
  end

  # TODO: This validation should check the configuration version
  # against the current migration version and they should match.
  # unless version == record.class::VERSION
  #   record.errors.add(:version, "\"#{version}\" is not the correct version: \"#{record.class::VERSION}\"")
  # end
end