How do we want to export sets?
Currently, we have one method, export_set that handles a few things:
- it will export files (with default handling of local dev environment)
- it will transform an ActiveSet instance and export that (with default handling of the request type)
This method has no relationship with process_set (the convenience method that composes filtering, sorting, and paginating).
Question 1
Do we split the current export_set method into two separate methods:
transform_set (analogous to filter_set, it simply wraps the call to the ActiveSet instance)
export_set (analogous to process_set, it is a convenience method that has the file exporting as well as the composition of filtering, sorting, and transforming)
Question 2
How do we handle exporting "complex object" sets? If there is an object that has any "has_many" relationships to other objects, it needs to be flattened in order to transform it (transformations are to 2D formats like CSV). The simplest approach is to split each "complex object" into a collection of "simple objects" where the has_many relationships are broken down into their combinatorial pairs.
Here is a sample implementation of that logic:
def exportable_rows_for(set, base_name:, each_has_many: [])
each_has_many = Array.wrap(each_has_many)
return set.map { |item| OpenStruct.new(base_name => item) } unless each_has_many.any?
set.flat_map do |item|
each_has_many.flat_map do |has_many|
if item.send(has_many).any?
association_name = has_many.to_s.singularize
item.send(has_many).map { |association| OpenStruct.new(base_name => item, association_name => association) }
else
OpenStruct.new(base_name => item)
end
end
end
end
Should such a method live in the gem? If so, should the convenience export_set method use it? If so, how do we give the caller full control over its use thru the convenience method?
How do we want to export sets?
Currently, we have one method,
export_setthat handles a few things:This method has no relationship with
process_set(the convenience method that composes filtering, sorting, and paginating).Question 1
Do we split the current
export_setmethod into two separate methods:transform_set(analogous tofilter_set, it simply wraps the call to the ActiveSet instance)export_set(analogous toprocess_set, it is a convenience method that has the file exporting as well as the composition of filtering, sorting, and transforming)Question 2
How do we handle exporting "complex object" sets? If there is an object that has any "has_many" relationships to other objects, it needs to be flattened in order to transform it (transformations are to 2D formats like CSV). The simplest approach is to split each "complex object" into a collection of "simple objects" where the has_many relationships are broken down into their combinatorial pairs.
Here is a sample implementation of that logic:
Should such a method live in the gem? If so, should the convenience
export_setmethod use it? If so, how do we give the caller full control over its use thru the convenience method?