Module: Metasploit::Model::NilifyBlanks

Extended by:
ActiveSupport::Concern
Defined in:
lib/metasploit/model/nilify_blanks.rb

Overview

Registers before validation callback to convert the given attributes to nil if they are blank. This can be used to normalize empty attributes to NULL in the database so queries don't have to handle both = '' and IS NULL.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#nilify_blanksvoid

This method returns an undefined value.

Before validation callback to change any attributes in Metasploit::Model::NilifyBlanks::ClassMethods#nilify_blank_attribute_set that are blank to nil.


40
41
42
43
44
45
46
47
48
# File 'lib/metasploit/model/nilify_blanks.rb', line 40

def nilify_blanks
  self.class.nilify_blank_attribute_set.each do |attribute|
    value = send(attribute)

    if value.respond_to? :blank? and value.blank?
      send("#{attribute}=", nil)
    end
  end
end