Module: Scratch::Concerns::Nilify::ClassMethods

Defined in:
lib/scratch/concerns/nilify.rb

Instance Method Summary collapse

Instance Method Details

#nilify(options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/scratch/concerns/nilify.rb', line 7

def nilify(options = {})
  options = HashWithIndifferentAccess.new options

  options[:before] ||= :validation
  options[:when]   ||= :blank?
  options[:name]   ||=
    "nilify_before_#{options[:before]}_when_#{options[:when]}"

  instance_eval do
    normalize options.merge(set: nil)
  end
end