Sha256: 82f571a1f1e346961e9e3e0e6967157f72c8bd7896820ce270d20df296414051

Contents?: true

Size: 565 Bytes

Versions: 5

Compression:

Stored size: 565 Bytes

Contents

module BusinessFlow
  # Validate that a given value is not nil, but allow blank/empty values.
  class NotNilValidator < ActiveModel::Validator
    # :reek:NilCheck :reek:UtilityFunction
    # Dear reek -- I didn't decided the ActiveModel Validator API, I just
    # have to live with it.
    def validate(record)
      requirements = record.class.requirements || []
      requirements.each do |attribute|
        value = record.read_attribute_for_validation(attribute)
        record.errors[attribute] << 'must not be nil' if value.nil?
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
business_flow-0.6.0 lib/business_flow/not_nil_validator.rb
business_flow-0.5.2 lib/business_flow/not_nil_validator.rb
business_flow-0.5.1 lib/business_flow/not_nil_validator.rb
business_flow-0.5.0 lib/business_flow/not_nil_validator.rb
business_flow-0.4.4 lib/business_flow/not_nil_validator.rb