Module: AutoSet::ActiveRecord::ClassMethods

Defined in:
lib/auto_set/active_record.rb

Instance Method Summary collapse

Instance Method Details

#auto_set(column, parents, options = {}) ⇒ Object


6
7
8
9
10
11
12
# File 'lib/auto_set/active_record.rb', line 6

def auto_set(column, parents, options = {})
  before = (parents.is_a?(Hash) ? parents : options).delete(:before)

  callback = [:save, :create, :validation].include?(before) ? :"before_#{before}" : :before_save

  self.send callback, SetColumn.new(column, parents, options)
end