Class: ActiveAdmin::CSVBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/active_admin/csv_builder.rb

Overview

CSVBuilder stores CSV configuration

Usage example:

csv_builder = CSVBuilder.new
csv_builder.column :id
csv_builder.column("Name") { |resource| resource.full_name }

Defined Under Namespace

Classes: Column

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ CSVBuilder

Returns a new instance of CSVBuilder.



26
27
28
29
# File 'lib/active_admin/csv_builder.rb', line 26

def initialize(&block)
  @columns = []
  instance_eval &block if block_given?
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



24
25
26
# File 'lib/active_admin/csv_builder.rb', line 24

def columns
  @columns
end

Class Method Details

.default_for_resource(resource) ⇒ Object

Return a default CSVBuilder for a resource The CSVBuilder’s columns would be Id followed by this resource’s content columns



15
16
17
18
19
20
21
22
# File 'lib/active_admin/csv_builder.rb', line 15

def self.default_for_resource(resource)
  new.tap do |csv_builder|
    csv_builder.column(:id)
    resource.content_columns.each do |content_column|
      csv_builder.column(content_column.name.to_sym)
    end
  end
end

Instance Method Details

#column(name, &block) ⇒ Object

Add a column



32
33
34
# File 'lib/active_admin/csv_builder.rb', line 32

def column(name, &block)
  @columns << Column.new(name, block)
end