Class: SampleManifest::Uploader
- Inherits:
-
Object
- Object
- SampleManifest::Uploader
- Includes:
- ActiveModel::Validations
- Defined in:
- app/models/sample_manifest/uploader.rb
Overview
Class SampleManifest::Uploader provides an interface for uploading sample manifests from a controller
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#override ⇒ Object
readonly
Returns the value of attribute override.
-
#tag_group ⇒ Object
readonly
Returns the value of attribute tag_group.
-
#upload ⇒ Object
readonly
Returns the value of attribute upload.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#initialize(file, configuration, user, override) ⇒ Uploader
constructor
A new instance of Uploader.
-
#run! ⇒ Object
rubocop:disable Metrics/MethodLength.
Constructor Details
#initialize(file, configuration, user, override) ⇒ Uploader
Returns a new instance of Uploader.
21 22 23 24 25 26 27 28 29 |
# File 'app/models/sample_manifest/uploader.rb', line 21 def initialize(file, configuration, user, override) @file = file @configuration = configuration || SequencescapeExcel::NullObjects::NullConfiguration.new @user = user @override = override @tag_group = create_tag_group @upload = SampleManifestExcel::Upload::Base.new(file: file, column_list: self.configuration.columns.all, override: override) end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
12 13 14 |
# File 'app/models/sample_manifest/uploader.rb', line 12 def configuration @configuration end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
12 13 14 |
# File 'app/models/sample_manifest/uploader.rb', line 12 def file @file end |
#override ⇒ Object (readonly)
Returns the value of attribute override.
12 13 14 |
# File 'app/models/sample_manifest/uploader.rb', line 12 def override @override end |
#tag_group ⇒ Object (readonly)
Returns the value of attribute tag_group.
12 13 14 |
# File 'app/models/sample_manifest/uploader.rb', line 12 def tag_group @tag_group end |
#upload ⇒ Object (readonly)
Returns the value of attribute upload.
12 13 14 |
# File 'app/models/sample_manifest/uploader.rb', line 12 def upload @upload end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
12 13 14 |
# File 'app/models/sample_manifest/uploader.rb', line 12 def user @user end |
Instance Method Details
#run! ⇒ Object
rubocop:disable Metrics/MethodLength
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/models/sample_manifest/uploader.rb', line 31 def run! # rubocop:disable Metrics/MethodLength # Validation outside the transaction because we want to return the errors return false unless valid? # Start the upload so that we can prevent concurrent uploads upload.sample_manifest.start! # Rails 6.1 doesn't allow return value from transaction block success = ActiveRecord::Base.transaction do raise ActiveRecord::Rollback unless process_upload_and_callbacks true end # Return from the function if the transaction succeeded return true if success # Else, return false and extract the errors extract_errors upload.fail false end |