Class: SampleManifest::Uploader

Inherits:
Object
  • Object
show all
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

Author:

  • Genome Research Ltd.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, configuration, user, override) ⇒ Uploader

Returns a new instance of Uploader.


20
21
22
23
24
25
26
27
28
# File 'app/models/sample_manifest/uploader.rb', line 20

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

#configurationObject (readonly)

Returns the value of attribute configuration.


12
13
14
# File 'app/models/sample_manifest/uploader.rb', line 12

def configuration
  @configuration
end

#fileObject (readonly)

Returns the value of attribute file.


12
13
14
# File 'app/models/sample_manifest/uploader.rb', line 12

def file
  @file
end

#overrideObject (readonly)

Returns the value of attribute override.


12
13
14
# File 'app/models/sample_manifest/uploader.rb', line 12

def override
  @override
end

#tag_groupObject (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

#uploadObject (readonly)

Returns the value of attribute upload.


12
13
14
# File 'app/models/sample_manifest/uploader.rb', line 12

def upload
  @upload
end

#userObject (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


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/models/sample_manifest/uploader.rb', line 30

def run!
  ActiveRecord::Base.transaction do
    return false unless valid?

    return true if process_upload_and_callbacks

    # One of our post processing checks failed, something went wrong, so we
    # roll everything back
    raise ActiveRecord::Rollback
  end

  extract_errors
  upload.fail
  false
end