Class: ActiveModel::Validations::TwinValidator

Inherits:
EachValidator
  • Object
show all
Defined in:
lib/twin_validator.rb

Defined Under Namespace

Modules: HelperMethods

Instance Method Summary collapse

Instance Method Details

#check_validity!Object

Raises:

  • (ArgumentError)


6
7
8
9
# File 'lib/twin_validator.rb', line 6

def check_validity!
  raise ArgumentError, "An Enumerable object is required and must be supplied as the " <<
                        ":twins option of the configuration hash" unless options[:twins].respond_to?(:each)
end

#validate_each(record, attribute, value) ⇒ Object



11
12
13
14
15
16
# File 'lib/twin_validator.rb', line 11

def validate_each(record, attribute, value)
  options[:twins].each do |twin|
    value = record.send(:read_attribute_for_validation, twin)
    record.errors.add_on_blank(attribute, options[:message]) if value
  end
end