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
29
30
31
32
# 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,
    start_row: SampleManifestExcel::FIRST_ROW,
    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


34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/models/sample_manifest/uploader.rb', line 34

def run!
  return false unless valid?

  if upload.process(tag_group)
    upload.complete
    upload.broadcast_sample_manifest_updated_event(user)
    true
  else
    extract_errors
    upload.fail
    false
  end
end