Module: CsvRowModel::Export::DynamicColumns
- Extended by:
- ActiveSupport::Concern
- Included in:
- CsvRowModel::Export
- Defined in:
- lib/csv_row_model/export/dynamic_columns.rb
Class Method Summary collapse
-
.define_dynamic_attribute_method(column_name) ⇒ Object
protected
Define default attribute method for a dynamic_column.
-
.dynamic_column(column_name, options = {}) ⇒ Object
protected
See Model::DynamicColumns#dynamic_column.
Instance Method Summary collapse
-
#formatted_attributes ⇒ Object
See Model::Columns#formatted_attributes.
-
#to_row ⇒ Array
An array of public_send(column_name) of the CSV model.
Class Method Details
.define_dynamic_attribute_method(column_name) ⇒ Object (protected)
Define default attribute method for a dynamic_column
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/csv_row_model/export/dynamic_columns.rb', line 31 def define_dynamic_attribute_method(column_name) define_method(column_name) do context.public_send(column_name).map do |header_model| self.class.format_cell( public_send(self.class.singular_dynamic_attribute_method_name(column_name), header_model), column_name, self.class.dynamic_index(column_name), context ) end end define_method(singular_dynamic_attribute_method_name(column_name)) { |header_model| header_model } end |
.dynamic_column(column_name, options = {}) ⇒ Object (protected)
See Model::DynamicColumns#dynamic_column
24 25 26 27 |
# File 'lib/csv_row_model/export/dynamic_columns.rb', line 24 def dynamic_column(column_name, ={}) super define_dynamic_attribute_method(column_name) end |
Instance Method Details
#formatted_attributes ⇒ Object
See Model::Columns#formatted_attributes
16 17 18 |
# File 'lib/csv_row_model/export/dynamic_columns.rb', line 16 def formatted_attributes super.merge(formatted_attributes_from_column_names(self.class.dynamic_column_names)) end |
#to_row ⇒ Array
Returns an array of public_send(column_name) of the CSV model.
11 12 13 |
# File 'lib/csv_row_model/export/dynamic_columns.rb', line 11 def to_row super.flatten end |