Skip to content

Commit 6d3f9f4

Browse files
committed
constantize unchaged variables
1 parent fd2737f commit 6d3f9f4

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

lib/active_admin_import/model.rb

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@ class Model
99
include ActiveModel::Validations
1010
include ActiveModel::Validations::Callbacks
1111

12+
module CONST
13+
ZIP_TYPE = 'application/zip'.freeze
14+
TMP_FILE = 'active-admin-import-unzipped'.freeze
15+
CSV_TYPES = %w(
16+
text/csv
17+
text/csv
18+
text/x-comma-separated-values
19+
text/comma-separated-values
20+
application/csv
21+
application/vnd.ms-excel
22+
application/vnd.msexcel
23+
).freeze
24+
end
25+
1226
validates :file, presence: {
1327
message: ->(*_) { I18n.t('active_admin_import.no_file_error') }
1428
}, unless: ->(me) { me.new_record? }
@@ -66,7 +80,7 @@ def persisted?
6680
end
6781

6882
def archive?
69-
file_type == 'application/zip'
83+
file_type == CONST::ZIP_TYPE
7084
end
7185

7286
alias to_hash attributes
@@ -90,24 +104,15 @@ def encode_file
90104

91105
def unzip_file
92106
Zip::File.open(file_path) do |zip_file|
93-
self.file = Tempfile.new('active-admin-import-unzipped')
107+
self.file = Tempfile.new(CONST::TMP_FILE)
94108
data = zip_file.entries.select(&:file?).first.get_input_stream.read
95109
file << data
96110
file.close
97111
end
98112
end
99113

100114
def csv_allowed_types
101-
[
102-
'text/csv',
103-
'text/x-csv',
104-
'text/x-comma-separated-values',
105-
'text/comma-separated-values',
106-
'application/csv',
107-
'application/vnd.ms-excel',
108-
'application/vnd.msexcel'
109-
110-
]
115+
CONST::CSV_TYPES
111116
end
112117

113118
def correct_content_type

0 commit comments

Comments
 (0)