Class: LibPoolNormTubeGenerator

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
app/models/lib_pool_norm_tube_generator.rb

Overview

rubocop:todo Style/Documentation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(barcode, user, study) ⇒ LibPoolNormTubeGenerator

Returns a new instance of LibPoolNormTubeGenerator.


13
14
15
16
17
# File 'app/models/lib_pool_norm_tube_generator.rb', line 13

def initialize(barcode, user, study)
  self.plate = barcode
  @user = user
  @study = study
end

Instance Attribute Details

#asset_groupObject (readonly)

Returns the value of attribute asset_group.


6
7
8
# File 'app/models/lib_pool_norm_tube_generator.rb', line 6

def asset_group
  @asset_group
end

#plateObject

Returns the value of attribute plate.


5
6
7
# File 'app/models/lib_pool_norm_tube_generator.rb', line 5

def plate
  @plate
end

#studyObject (readonly)

Returns the value of attribute study.


6
7
8
# File 'app/models/lib_pool_norm_tube_generator.rb', line 6

def study
  @study
end

#userObject (readonly)

Returns the value of attribute user.


6
7
8
# File 'app/models/lib_pool_norm_tube_generator.rb', line 6

def user
  @user
end

Instance Method Details

#create!Object

rubocop:todo Metrics/MethodLength


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/models/lib_pool_norm_tube_generator.rb', line 44

def create! # rubocop:todo Metrics/AbcSize
  if valid?
    begin
      ActiveRecord::Base.transaction do
        lib_pool_tubes.each do |tube|
          pass_and_complete(tube)
          pass_and_complete(create_lib_pool_norm_tube(tube))
        end

        @asset_group =
          AssetGroup.create!(
            assets: destination_tubes.map(&:receptacle),
            study: study,
            name: "#{plate.human_barcode}_qc_completed_tubes"
          )
      end
      true
    rescue => e
      Rails.logger.error("Pool generation error: #{e.message}")
      Rails.logger.error(e.backtrace)
      false
    end
  end
end

#destination_tubesObject


39
40
41
# File 'app/models/lib_pool_norm_tube_generator.rb', line 39

def destination_tubes
  @destination_tubes ||= []
end

#lib_pool_tubesObject


31
32
33
34
35
36
37
# File 'app/models/lib_pool_norm_tube_generator.rb', line 31

def lib_pool_tubes
  @lib_pool_tubes ||=
    plate
      .children
      .select { |c| c.is_a?(StockMultiplexedLibraryTube) }
      .reject { |tube| tube.state == 'failed' || tube.state == 'qc_complete' || tube.state == 'cancelled' }
end

#set_plate(barcode) ⇒ Object


27
28
29
# File 'app/models/lib_pool_norm_tube_generator.rb', line 27

def set_plate(barcode)
  Plate.with_barcode(barcode).includes(wells: { requests: %i[request_type target_asset] }).first
end

#transfer_templateObject


19
20
21
# File 'app/models/lib_pool_norm_tube_generator.rb', line 19

def transfer_template
  @transfer_template ||= TransferTemplate.find_by!(transfer_class_name: 'Transfer::BetweenTubesBySubmission')
end