Module: NullifyIfBlank

Extended by:
ActiveSupport::Concern
Included in:
Clusters::Agents::ActivityEvent, Clusters::Platforms::Kubernetes, Environment
Defined in:
app/models/concerns/nullify_if_blank.rb

Overview

Helper that sets attributes to nil prior to validation if they are blank (are false, empty or contain only whitespace), to avoid unnecessarily persisting empty strings.

Model usage:

class User < ApplicationRecord
  include NullifyIfBlank

  nullify_if_blank :name, :email
end

Test usage:

RSpec.describe User do
  it { is_expected.to nullify_if_blank(:name) }
  it { is_expected.to nullify_if_blank(:email) }
end