Sha256: b3148684a55e2bf26023714af4093a8d3ae768215026bbb2f87c94fe4eeb71b4
Contents?: true
Size: 1.88 KB
Versions: 1
Compression:
Stored size: 1.88 KB
Contents
module GiJob module Models module Concerns module GiJobFileable extend ActiveSupport::Concern included do # begin included mount_uploader :file, GiLogFileCarrierWaveUploader belongs_to :gi_job_transaction end # end included class_methods do # begin class_methods def create_file!( gi_job_transaction:, file_path: nil, uploaded_file: nil, rows: 0 ) file = nil name = nil size = 0 if file_path.present? name = File.basename(file_path) file = File.open(file_path) size = File.size(file_path) elsif uploaded_file.present? GiJob.logger.ap(uploaded_file: uploaded_file) name = File.basename(uploaded_file.original_filename) file = uploaded_file size = uploaded_file.size end self.create!({ gi_job_transaction: gi_job_transaction, name: name, file: file, rows: rows, size: size, }) end def create_action_dispatch_uploaded_file(file, file_name) params = { :filename => "#{file_name}", :type => File.extname(file_name).delete('.'), :tempfile => file } # logger.ap({"method": "base64_conversion", params: params}) ActionDispatch::Http::UploadedFile.new(params) end end # end class_methods def data_source self.file.force_encoding('utf-8') end def delete_data_source! self.update!({file: nil}) end def has_file? self.file_blob.present? || self.file.present? end end # end GiJobFileable end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
gi_job-0.1.3 | lib/gi_job/models/concerns/gi_job_fileable.rb |