@@ -6,9 +6,11 @@ module Csv2db::ActiveStorageAdapter
66 MAX_EXPIRY = 7 . days . to_s . freeze
77
88 included do
9- has_one_attached :csv_upload
9+ has_one_attached Csv2db . config . file_attachment_name
1010
1111 validate :check_file_extension
12+
13+ alias_method :file_attachment , Csv2db . config . file_attachment_name
1214 end
1315
1416 def file = ( file )
@@ -17,7 +19,7 @@ def file=(file)
1719
1820 filename = file . original_filename
1921
20- csv_upload . attach (
22+ file_attachment . attach (
2123 io : File . open ( file ) ,
2224 filename : filename ,
2325 content_type : file . content_type
@@ -27,30 +29,30 @@ def file=(file)
2729 end
2830
2931 def expiring_link ( expires_in : MAX_EXPIRY )
30- return unless csv_upload . present?
32+ return unless file_attachment . present?
3133
32- set_current_host_if_local
34+ set_current_host
3335
34- csv_upload . service_url ( expires_in : expires_in . to_i , disposition : 'attachment' )
36+ file_attachment . service_url ( expires_in : expires_in . to_i , disposition : 'attachment' )
3537 end
3638
3739 private
3840
39- def set_current_host_if_local
40- return unless Rails . application . config . active_storage . service == :local
41+ def set_current_host
42+ return unless %i[ test local ] . include? ( Rails . application . config . active_storage . service )
4143
4244 ActiveStorage ::Current . host = ReportGenerator . config . local_storage_host
4345 end
4446
4547 def check_file_extension
4648 # very basic check of file extension
47- errors . add ( :file , I18n . t ( 'shared.file_processor.incorrect_file_type' ) ) unless csv_upload . blob . content_type == FILE_TYPE
49+ errors . add ( :file , I18n . t ( 'shared.file_processor.incorrect_file_type' ) ) unless file_attachment . blob . content_type == FILE_TYPE
4850 end
4951
5052 def file_data
5153 return @file_data if @file_data . present?
5254
53- csv_upload . blob . open do |blob |
55+ file_attachment . blob . open do |blob |
5456 @file_data = str_to_utf8 ( blob . read )
5557 end
5658
0 commit comments