Module: Tableficate::Utils

Defined in:
lib/tableficate/utils.rb

Class Method Summary collapse

Class Method Details

.find_column_type(scope, name) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/tableficate/utils.rb', line 11

def self.find_column_type(scope, name)
  name = name.to_s
  column = scope.columns.detect{|column| column.name == name} ||
  (
    (scope.respond_to?(:joins_values) ? scope.joins_values : []) +
    (scope.respond_to?(:includes_values) ? scope.includes_values : [])
  ).uniq.map{|join|
    # convert string joins to table names
    if join.is_a?(String)
      join.scan(/\G(?:(?:,|\bjoin\s)\s*(\w+))/i)
    else
      join
    end
  }.flatten.map{|table_name|
    ActiveRecord::Base::connection_pool.columns[table_name.to_s.tableize]
  }.flatten.detect{|column|
    column.name == name
  }
  column.try(:type)
end

.template_path(template, partial, theme = '') ⇒ Object



3
4
5
6
7
8
9
# File 'lib/tableficate/utils.rb', line 3

def self.template_path(template, partial, theme = '')
  file = File.join(['tableficate', theme, partial].delete_if(&:blank?))

  file = File.join(['tableficate', partial]) if not theme.blank? and not template.lookup_context.exists?(file, [], true)

  file
end