Module: NilifyBlanks::ClassMethods

Defined in:
lib/nilify_blanks.rb

Constant Summary collapse

DEFAULT_TYPES =
[:string, :text, :citext]
DEFAULT_CALLBACK =
:validation
@@define_nilify_blank_methods_lock =
Mutex.new

Instance Method Summary collapse

Instance Method Details

#define_attribute_methodsObject

This overrides the underlying rails method that defines attribute methods. This must be thread safe, just like the underlying method.



20
21
22
23
24
# File 'lib/nilify_blanks.rb', line 20

def define_attribute_methods
  if super
    define_nilify_blank_methods
  end
end

#nilify_blanks(options = {}) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/nilify_blanks.rb', line 26

def nilify_blanks(options = {})
  self.nilify_blanks_options = options

  # Normally we wait for rails to define attribute methods, but we could be calling this after this has already been done.
  # If so, let's just immediately generate nilify blanks methods.
  #
  define_nilify_blank_methods if @attribute_methods_generated
end