Module: EasyExport::ClassMethods
- Defined in:
- lib/easy_export.rb
Instance Method Summary collapse
- #export_fields ⇒ Object
- #export_partial ⇒ Object
- #export_scope ⇒ Object
-
#exportable(&block) ⇒ Object
Declare this method in your model class to define the export configuration.
Instance Method Details
#export_fields ⇒ Object
34 |
# File 'lib/easy_export.rb', line 34 def export_fields; @export_config.fields end |
#export_partial ⇒ Object
32 |
# File 'lib/easy_export.rb', line 32 def export_partial; @export_config.partial end |
#export_scope ⇒ Object
33 |
# File 'lib/easy_export.rb', line 33 def export_scope; @export_config.scope end |
#exportable(&block) ⇒ Object
Declare this method in your model class to define the export configuration.
The block will be executed in the context of the ExportConfig, e.g:
exportable do
scope -> { ['some records', ...] }
fields [
['Header 1', -> { value to return }],
['Header 2', :method_name],
['Header 3', 'static value'], ...
]
end
scope: an object that responds to #call and returns a collection of instances fields: an array of tuples where the 1st element is the Header name
and the 2nd is a proc, symbol, or static value to be instance
exec'ed, called as a method on the instance, or just returned, respectively.
26 27 28 29 30 |
# File 'lib/easy_export.rb', line 26 def exportable(&block) @export_config ||= ExportConfig.new @export_config.partial = name.demodulize.underscore.pluralize @export_config.instance_exec &block end |