Class: AutoSet::SetColumn

Inherits:
Object
  • Object
show all
Defined in:
lib/auto_set/set_column.rb

Instance Method Summary collapse

Constructor Details

#initialize(column, parents, options = {}) ⇒ SetColumn

Returns a new instance of SetColumn


3
4
5
6
7
8
9
10
11
12
13
# File 'lib/auto_set/set_column.rb', line 3

def initialize(column, parents, options = {})
  @column = column

  if parents.is_a? Hash
    @options = parents.reverse_merge from: :code
  else
    @options = options || {}
    @parents = parents
    @parents = @parents.is_a?(Array) ? @parents : [ @parents ]
  end
end

Instance Method Details

#before_create(record) ⇒ Object


24
25
26
# File 'lib/auto_set/set_column.rb', line 24

def before_create(record)
  before_save record
end

#before_save(record) ⇒ Object


15
16
17
18
19
20
21
22
# File 'lib/auto_set/set_column.rb', line 15

def before_save(record)
  @record = record
  if @parents.present?
    direct
  else
    from_column
  end
end

#before_validation(record) ⇒ Object


28
29
30
# File 'lib/auto_set/set_column.rb', line 28

def before_validation(record)
  before_save record
end