lib/sepa/attribute_checks.rb
# Checks presence and length of an attribute
#
# @param attribute [Symbol] the attribute to validate
# @param length [Integer] the maximum length of the attribute
# @param error_message [#to_s] the error message to display if the validation fails
Checks presence and length of an attribute
Checks presence and length of an attribute
def check_presence_and_length(attribute, length, error_message)
      check = true
      check &&= send(attribute)
      check &&= send(attribute).respond_to? :size
      check &&= send(attribute).size < length
      check &&= !send(attribute).empty?
      errors.add(attribute, error_message) unless check
    end
def check_presence_and_length ( attribute , length , error_message ) check = true check &&= send ( attribute ) check &&= send ( attribute ) . respond_to? :size check &&= send ( attribute ) . size < length check &&= ! send ( attribute ) . empty? errors . add ( attribute , error_message ) unless check end
Checks presence and length of an attribute
Checks presence and length of an attribute
attribute
the attribute to validate
the attribute to validate
length
the maximum length of the attribute
the maximum length of the attribute
error_message
the error message to display if the validation fails
the error message to display if the validation fails