module EasyExport::ClassMethods
Public Instance Methods
export_fields()
click to toggle source
# File lib/easy_export.rb, line 34 def export_fields; @export_config.fields end
export_partial()
click to toggle source
# File lib/easy_export.rb, line 32 def export_partial; @export_config.partial end
export_scope()
click to toggle source
# File lib/easy_export.rb, line 33 def export_scope; @export_config.scope end
exportable(&block)
click to toggle source
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.
# 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