Module: Exportable::Utils

Included in:
ExportMethods::CsvExporter, ExportMethods::XlsExporter, ExportMethods::XmlExporter
Defined in:
lib/exportable/utils.rb

Overview

Utiity methods used for gem

Instance Method Summary collapse

Instance Method Details

#get_export_options(model, options) ⇒ Object

Compute exportable options after overriding preferences



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/exportable/utils.rb', line 5

def get_export_options(model, options)
  default_options = { only: model.attribute_names.map(&:to_sym),
                      except: [],
                      methods: [],
                      header: true }
  options = default_options.merge(options)
  unless options[:only].is_a?(Array) && options[:except].is_a?(Array) && options[:methods].is_a?(Array)
    raise ArgumentError, 'Exportable: Expecting Array type for field options'
  end
  fields = options[:only] - options[:except] + options[:methods]
  { fields: fields, header: options[:header] }
end