Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom SolidusImporter::Import strategy to read CSV files #61

Open
cesartalves opened this issue Apr 8, 2021 · 1 comment
Open
Labels

Comments

@cesartalves
Copy link
Contributor

cesartalves commented Apr 8, 2021

Right now SolidusImporter::ProcessImport is reading the CSV file by doing a File.read on the import file path.

def scan
      data = CSV.parse(
        File.read(@import.file.path),
        headers: true,
        encoding: 'UTF-8',
        header_converters: ->(h) { h.strip }
      )
      prepare_rows(data)
end

However, on some projects that path may not be available depending on which customizations have been applied to Paperclip or ActiveStorage.
On a project I'm working on the files are sent directly to AWS, even on development, and their bucket path is interpolated in such a way that the @import.file local path can't be determined.

Therefore it would be useful to allow user-customizable strategies for reading the content from the file. E.g.:

SolidusImporter.config do |c|
  c.import_file_reader = -> (import) {
     open(@import.file.public_url)
  }
end

def scan
      raw_content = SolidusImporter::Config.import_file_reader.call(@import)
      data = CSV.parse(
        raw_content,
        headers: true,
        encoding: 'UTF-8',
        header_converters: ->(h) { h.strip }
      )
      prepare_rows(data)
end

Or any other approach may also be viable as long as we allow this to me easily customizable.

@stale
Copy link

stale bot commented Jun 9, 2021

This issue has been automatically marked as stale because it has not had recent activity. It might be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jun 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant