class ActiveModel::Validations::PresenceOfFlagsValidator

A simple EachValidator that will check for the presence of the flags specified

Public Instance Methods

validate_each(record, attribute, value) click to toggle source
# File lib/flag_shih_tzu/validators.rb, line 20
def validate_each(record, attribute, value)
  value = record.send(:read_attribute_for_validation, attribute)
  check_flag(record, attribute)
  record.errors.add(attribute, :blank, options) if value.blank? || value == 0
end

Private Instance Methods

check_flag(record, attribute) click to toggle source
# File lib/flag_shih_tzu/validators.rb, line 28
def check_flag(record, attribute)
  unless record.class.flag_columns.include? attribute.to_s
    raise ArgumentError.new("#{attribute} is not one of the flags columns (#{record.class.flag_columns.join(', ')})")
  end
end