Maintenance: Add missing gem 'csv' to gemfile, and only load it when it's actuallly used.

This commit is contained in:
Martin Gruner 2021-09-02 09:24:58 +02:00
parent 60c9c45c96
commit ce4ca035d6
4 changed files with 9 additions and 4 deletions

View file

@ -116,6 +116,9 @@ gem 'diffy'
# feature - excel output
gem 'writeexcel', require: false
# feature - csv import/export
gem 'csv', require: false
# feature - device logging
gem 'browser'

View file

@ -165,6 +165,7 @@ GEM
crack (0.4.5)
rexml
crass (1.0.6)
csv (3.2.0)
daemons (1.4.1)
dalli (2.7.11)
debug_inspector (1.1.0)
@ -667,6 +668,7 @@ DEPENDENCIES
coffeelint
composite_primary_keys
coveralls
csv
daemons
dalli
delayed_job_active_record

View file

@ -1,7 +1,5 @@
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
require 'csv'
module CanCsvImport
extend ActiveSupport::Concern
@ -59,6 +57,7 @@ returns
raise Exceptions::UnprocessableEntity, "Unable to read file '#{data[:file]}': #{e.inspect}"
end
require 'csv' # Only load it when it's really needed to save memory.
header, *rows = ::CSV.parse(data[:string], **data[:parse_params])
header&.each do |column|
@ -296,6 +295,8 @@ returns
end
rows_to_add = []
end
require 'csv' # Only load it when it's really needed to save memory.
::CSV.generate(**params) do |csv|
csv << header
rows.each do |row|

View file

@ -1,7 +1,5 @@
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
require 'csv'
class Translation < ApplicationModel
before_create :set_initial
after_create :cache_clear
@ -407,6 +405,7 @@ Get source file at https://i18n.zammad.com/api/v1/translations_empty_translation
params = {
col_sep: ',',
}
require 'csv' # Only load it when it's really needed to save memory.
rows = ::CSV.parse(content, params)
rows.shift # remove header