Method: Marty::DataExporter.export_headers

Defined in:
lib/marty/data_exporter.rb

.export_headers(klass, attrs = nil, exclude_attrs = []) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/marty/data_exporter.rb', line 119

def self.export_headers(klass, attrs = nil, exclude_attrs = [])
  col_types = Marty::DataConversion.col_types(klass)

  attr_list_raw = (attrs || col_types.keys).map(&:to_s) - exclude_attrs
  attr_list = get_attrs_in_order(klass, attr_list_raw)

  attr_list.map do |c|
    type = col_types[c]

    next c unless type.is_a?(Hash)

    # remove _id
    c = c[0..-4]
    assoc_keys = type[:assoc_keys]

    # if association has a single key, just use col name
    next c if assoc_keys.length == 1

    assoc_class = type[:assoc_class]

    export_headers(assoc_class, assoc_keys).map { |k| "#{c}__#{k}" }
  end
end