Module: CsvRowModel::Export
- Extended by:
- ActiveSupport::Concern
- Includes:
- Attributes, DynamicColumns
- Defined in:
- lib/csv_row_model/export.rb,
lib/csv_row_model/export/file.rb,
lib/csv_row_model/export/attributes.rb,
lib/csv_row_model/export/file_model.rb,
lib/csv_row_model/export/dynamic_columns.rb
Overview
Include this to with Model to have a RowModel for exporting to CSVs.
Defined Under Namespace
Modules: Attributes, DynamicColumns, FileModel Classes: File
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#source_model ⇒ Object
readonly
Returns the value of attribute source_model.
Class Method Summary collapse
Instance Method Summary collapse
- #initialize(source_model, context = {}) ⇒ Object
-
#to_row ⇒ Array
An array of public_send(column_name) of the CSV model.
- #to_rows ⇒ Object
Methods included from DynamicColumns
define_dynamic_attribute_method, dynamic_column, #formatted_attributes
Methods included from Attributes
column, define_attribute_method, format_cell, #formatted_attribute, #formatted_attributes, #formatted_attributes_from_column_names
Methods included from Model::Comparison
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
13 14 15 |
# File 'lib/csv_row_model/export.rb', line 13 def context @context end |
#source_model ⇒ Object (readonly)
Returns the value of attribute source_model.
13 14 15 |
# File 'lib/csv_row_model/export.rb', line 13 def source_model @source_model end |
Class Method Details
.setup(csv, context = {}, with_headers: true) ⇒ Object
34 35 36 |
# File 'lib/csv_row_model/export.rb', line 34 def setup(csv, context={}, with_headers: true) csv << headers(context) if with_headers end |
Instance Method Details
#initialize(source_model, context = {}) ⇒ Object
19 20 21 22 |
# File 'lib/csv_row_model/export.rb', line 19 def initialize(source_model, context={}) @source_model = source_model @context = OpenStruct.new(context) end |
#to_row ⇒ Array
Returns an array of public_send(column_name) of the CSV model.
29 30 31 |
# File 'lib/csv_row_model/export.rb', line 29 def to_row formatted_attributes.values end |
#to_rows ⇒ Object
24 25 26 |
# File 'lib/csv_row_model/export.rb', line 24 def to_rows [to_row] end |