Class: AdministrateExportable::ExporterService

Inherits:
Object
  • Object
show all
Defined in:
lib/administrate_exportable/exporter_service.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dashboard, resource_class, resources) ⇒ ExporterService

Returns a new instance of ExporterService.



9
10
11
12
13
# File 'lib/administrate_exportable/exporter_service.rb', line 9

def initialize(dashboard, resource_class, resources)
  @dashboard = dashboard
  @resource_class = resource_class
  @resources = resources
end

Class Method Details

.csv(dashboard, resource_class, resources) ⇒ Object



5
6
7
# File 'lib/administrate_exportable/exporter_service.rb', line 5

def self.csv(dashboard, resource_class, resources)
  new(dashboard, resource_class, resources).csv
end

Instance Method Details

#csvObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/administrate_exportable/exporter_service.rb', line 15

def csv
  CSV.generate(headers: true) do |csv|

    csv << headers

    collection.find_each do |record|
      csv << attributes_to_export.map do |attribute_key, attribute_type|
        record_attribute(record, attribute_key, attribute_type)
      end
    end
  end
end