Module: Kwatable::TableHelper

Defined in:
lib/kwatable/template/helper/table.rb

Instance Method Summary collapse

Instance Method Details

#table_check_modeling(table) ⇒ Object

return reason if table should be skip modeling



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/kwatable/template/helper/table.rb', line 48

def table_check_modeling(table)
  reason = nil
  if table['modeling'] == false
    reason = "table['modeling'] == false"
  elsif table['ident-columns'].length > 1
    reason = "compound primary key"
  elsif table['ident-columns'].length == 0
    reason = "no primary-key"
  end
  return reason
end

#table_class(table) ⇒ Object



19
20
21
# File 'lib/kwatable/template/helper/table.rb', line 19

def table_class(table)
  return table['class'] || Inflector.classify(table['name'])
end

#table_display_column(table) ⇒ Object



28
29
30
31
32
33
# File 'lib/kwatable/template/helper/table.rb', line 28

def table_display_column(table)
  column = table['display-column']
  column ||= table['columns'].find { |col| col['name'] == 'code' }
  column ||= table['columns'].find { |col| col['name'] == 'name' }
  return column
end

#table_ident_column(table) ⇒ Object



39
40
41
# File 'lib/kwatable/template/helper/table.rb', line 39

def table_ident_column(table)
  return table['columns'].find { |col| col['ident'] }
end

#table_ident_columns(table) ⇒ Object



35
36
37
# File 'lib/kwatable/template/helper/table.rb', line 35

def table_ident_columns(table)
  return table['columns'].find_all { |col| col['ident'] }
end

#table_model(table) ⇒ Object



23
24
25
26
# File 'lib/kwatable/template/helper/table.rb', line 23

def table_model(table)
  #return Inflector.singularize(table_name(table))
  return Inflector.underscore(table_class(table))
end

#table_name(table) ⇒ Object



14
15
16
17
# File 'lib/kwatable/template/helper/table.rb', line 14

def table_name(table)
  #return table['model-name'] || table['name']
  return table['name']
end

#table_referrer_column(table, column) ⇒ Object



43
44
45
# File 'lib/kwatable/template/helper/table.rb', line 43

def table_referrer_column(table, column)
  return table['columns'].find { |col| col['ref'] && col['ref'].__id__ ==  column.__id__ }
end