lib/soft_validation/soft_validations.rb
# Add a soft validation to a data instance.
# 
# @param attribute [Symbol]
#   a column attribute or :base
# @param message [String]
#   a message describing the soft validation to the user, i.e. what has gone wrong
# @param options [Hash]
#   legal keys are :failure_message and :success_message
Add a soft validation to a data instance.
Add a soft validation to a data instance .
def add(attribute, message, options = {})
      method = caller[0][/`(block\ in\ )*([^']*)'/, 2].to_sym 
      raise SoftValidationError, "can not add soft validation to [#{attribute}] - not a column name or 'base'" if !(['base'] + @instance.class.column_names).include?(attribute.to_s)
      raise SoftValidationError, 'no :attribute or message provided to soft validation' if attribute.nil? || message.nil? || message.length == 0
      options.merge!(
        method_instance: @instance.class.soft_validation_methods[method], 
        attribute: attribute,
        message: message,
      )
      sv = ::SoftValidation::SoftValidation.new(options)
      @soft_validations << sv
    end
def add ( attribute , message , options = { } ) method = caller [ 0 ] [ / `(block \  in \  )*([^']*)' / , 2 ] . to_sym raise SoftValidationError , "can not add soft validation to [#{attribute}] - not a column name or 'base'" if ! ( [ 'base' ] + @instance . class . column_names ) . include? ( attribute . to_s ) raise SoftValidationError , 'no :attribute or message provided to soft validation' if attribute . nil? || message . nil? || message . length == 0 options . merge! ( method_instance : @instance . class . soft_validation_methods [ method ] , attribute : attribute , message : message , ) sv = :: SoftValidation :: SoftValidation . new ( options ) @soft_validations << sv end
Add a soft validation to a data instance.
Add a soft validation to a data instance .
# this is impossible to test. # janky, the caller of this method, that is the method referenced in `soft_validate()`, used to get the fix for this Instance added # inspected to expose method values
attribute
a column attribute or :base
a column attribute or : base
message
a message describing the soft validation to the user, i.e. what has gone wrong
a message describing the soft validation to the user i . e . what has gone wrong
options
legal keys are :failure_message and :success_message
legal keys are : failure_message and : success_message