Class: ActiveAdmin::CSVBuilder
- 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
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
Class Method Summary collapse
-
.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.
Instance Method Summary collapse
-
#column(name, &block) ⇒ Object
Add a column.
-
#initialize(&block) ⇒ CSVBuilder
constructor
A new instance of CSVBuilder.
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
#columns ⇒ Object (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 |