Class: FeatureFlagUserXidsValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
app/validators/feature_flag_user_xids_validator.rb

Constant Summary collapse

USERXID_MAX_LENGTH =
256

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.validate_user_xids(record, attribute, user_xids, error_message_attribute_name) ⇒ Object


11
12
13
14
15
16
# File 'app/validators/feature_flag_user_xids_validator.rb', line 11

def validate_user_xids(record, attribute, user_xids, error_message_attribute_name)
  unless user_xids.is_a?(String) && !user_xids.match(/[\n\r\t]|,,/) && valid_xids?(user_xids.split(","))
    record.errors.add(attribute,
                      "#{error_message_attribute_name} must be a string of unique comma separated values each #{USERXID_MAX_LENGTH} characters or less")
  end
end

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object


6
7
8
# File 'app/validators/feature_flag_user_xids_validator.rb', line 6

def validate_each(record, attribute, value)
  self.class.validate_user_xids(record, attribute, value, attribute)
end