Class: Para::Exporter::Base
- Defined in:
- lib/para/exporter/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
-
.params_whitelist ⇒ Object
Override in subclass to add a params whitelist that are fetched from the request before initializing the exporter.
Instance Method Summary collapse
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
4 5 6 |
# File 'lib/para/exporter/base.rb', line 4 def model @model end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/para/exporter/base.rb', line 4 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/para/exporter/base.rb', line 4 def @options end |
Class Method Details
.params_whitelist ⇒ Object
Override in subclass to add a params whitelist that are fetched from the request before initializing the exporter
For example, if you want to export posts for a given category, you can add the ‘:category_id` param to your export link, and whitelist this param here with :
def self.params_whitelist
[:category_id]
end
It will be passed from the controller to the importer so it can be used to scope resources before exporting.
Note that you’ll manually need to scope the resources by overriding the #resources method.
If you need automatic scoping, please use the ‘:q` param that accepts ransack search params and applies it to the resources.
110 111 112 |
# File 'lib/para/exporter/base.rb', line 110 def self.params_whitelist [] end |
Instance Method Details
#file ⇒ Object
34 35 36 |
# File 'lib/para/exporter/base.rb', line 34 def file @file ||= GlobalID::Locator.locate(store(:file_gid)) end |
#file_name ⇒ Object
38 39 40 |
# File 'lib/para/exporter/base.rb', line 38 def file_name @file_name ||= [name, extension].join end |
#perform(model_name: nil, **options) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/para/exporter/base.rb', line 6 def perform(model_name: nil, **) @model = model_name && model_name.constantize @options = @name = model.try(:model_name).try(:route_key).try(:parameterize) # Render file and store it in a Library::File object, allowing us # to retrieve that file easily from the job and subsequent requests # file = Para::Library::File.new if file.respond_to?(:attachment?) file. = render else file..attach( io: render, filename: file_name, content_type: mime_type ) end file.save! store(:file_gid, file.to_global_id) # Ensure that `.perform_now` returns the exporter self end |